Class ValueManager
It maintains a value between the minimum and maximum values.
Each value can be modified using this class.
It gives a layer of abstraction as this class doesn't know about ProgressBar or Resource.
Namespace: TetraCreations.ProgressBarSystem
Assembly: cs.temp.dll.dll
Syntax
public class ValueManager : MonoBehaviour
Fields
_allowValueDecrease
Declaration
protected bool _allowValueDecrease
Field Value
Type | Description |
---|---|
bool |
_allowValueIncrease
Declaration
protected bool _allowValueIncrease
Field Value
Type | Description |
---|---|
bool |
_initialAllowValueDecrease
Declaration
protected bool _initialAllowValueDecrease
Field Value
Type | Description |
---|---|
bool |
_initialAllowValueIncrease
Declaration
protected bool _initialAllowValueIncrease
Field Value
Type | Description |
---|---|
bool |
_initialized
Declaration
protected bool _initialized
Field Value
Type | Description |
---|---|
bool |
_initialMaximum
Declaration
protected float _initialMaximum
Field Value
Type | Description |
---|---|
float |
_initialMinimum
Declaration
protected float _initialMinimum
Field Value
Type | Description |
---|---|
float |
_initialValue
Declaration
protected float _initialValue
Field Value
Type | Description |
---|---|
float |
_maximum
Declaration
protected float _maximum
Field Value
Type | Description |
---|---|
float |
_minimum
Declaration
protected float _minimum
Field Value
Type | Description |
---|---|
float |
_precisionTolerance
Declaration
protected float _precisionTolerance
Field Value
Type | Description |
---|---|
float |
_value
Declaration
protected float _value
Field Value
Type | Description |
---|---|
float |
_valueState
Declaration
protected ValueState _valueState
Field Value
Type | Description |
---|---|
ValueState |
Properties
AllowChanges
Allows or prevents any modification to the value.
Declaration
public bool AllowChanges { get; set; }
Property Value
Type | Description |
---|---|
bool |
AllowValueDecrease
Allows or prevents any decrease in value.
Declaration
public bool AllowValueDecrease { get; set; }
Property Value
Type | Description |
---|---|
bool |
AllowValueIncrease
Allows or prevents any increase in value.
Declaration
public bool AllowValueIncrease { get; set; }
Property Value
Type | Description |
---|---|
bool |
AtMaximum
Determines whether the ValueState is AtMaximum.
Declaration
public bool AtMaximum { get; }
Property Value
Type | Description |
---|---|
bool |
AtMinimum
Determines whether the ValueState is AtMinimum.
Declaration
public bool AtMinimum { get; }
Property Value
Type | Description |
---|---|
bool |
CurrentState
The current state of the value : AtMinimum, AtMaximum or InBetween.
Declaration
public ValueState CurrentState { get; }
Property Value
Type | Description |
---|---|
ValueState |
Initialized
Determines if the ValueManager is initialized and ready to be used.
Declaration
public bool Initialized { get; }
Property Value
Type | Description |
---|---|
bool |
LastMaximumValueChange
Returns the last change made to the maximum value.
Declaration
public float LastMaximumValueChange { get; }
Property Value
Type | Description |
---|---|
float |
LastMinimumValueChange
Returns the last change made to the minimum value.
Declaration
public float LastMinimumValueChange { get; }
Property Value
Type | Description |
---|---|
float |
LastOverflowAmount
Returns the last overflow amount that couldn't be applied to the value.
Declaration
public float LastOverflowAmount { get; }
Property Value
Type | Description |
---|---|
float |
LastValueChange
Returns the last change made to the value.
Declaration
public float LastValueChange { get; }
Property Value
Type | Description |
---|---|
float |
Maximum
The maximum value. Setter ensure that it's above Minimum.
Declaration
public float Maximum { get; set; }
Property Value
Type | Description |
---|---|
float |
MaximumAmountWithinLimits
The total amount between the limits, so it's the maximum value minus the minimum value.
Just because the minimum value can be different than zero.
Declaration
public float MaximumAmountWithinLimits { get; }
Property Value
Type | Description |
---|---|
float |
Minimum
The minimum value. Setter ensure that it's below the maximum.
Declaration
public float Minimum { get; set; }
Property Value
Type | Description |
---|---|
float |
MissingValue
Returns the difference between the maximum and the current value.
Declaration
public float MissingValue { get; }
Property Value
Type | Description |
---|---|
float |
MissingValuePercentage
Returns the percentage of missing value compared to the Maximum value.
It returns a float between 0f and 1f as it's a percentage.
Declaration
public float MissingValuePercentage { get; }
Property Value
Type | Description |
---|---|
float |
Percentage
Returns the value as percentage.
For example 75/100 will return 0.75f.
Declaration
public float Percentage { get; }
Property Value
Type | Description |
---|---|
float |
PrecisionTolerance
Used to compare the current value with Minimum and Maximum values, we can't compare float's equality.
We could tolerate a value of 99.98 to be equals to 100 for exemple.
Declaration
public float PrecisionTolerance { get; set; }
Property Value
Type | Description |
---|---|
float |
Value
The current value. Setter ensure it's clamped between the minimum and maximum.
Declaration
public float Value { get; set; }
Property Value
Type | Description |
---|---|
float |
ValueState
The current state of the ProgressBar : At Minimum, At Maximum, In Between.
Declaration
public ValueState ValueState { get; }
Property Value
Type | Description |
---|---|
ValueState |
Methods
AreEqual(float, float)
Compare two float value to determines if they are equal using the PrecisionTolerance variable to allow minor difference that doesn't matter.
Declaration
public bool AreEqual(float a, float b)
Parameters
Type | Name | Description |
---|---|---|
float | a | |
float | b |
Returns
Type | Description |
---|---|
bool |
CanDecrease()
Determines if the value can decrease.
Declaration
public virtual bool CanDecrease()
Returns
Type | Description |
---|---|
bool |
CanIncrease()
Determines if the value can increase.
Declaration
public virtual bool CanIncrease()
Returns
Type | Description |
---|---|
bool |
Decrease(float)
Decrease the value.
Declaration
public virtual float Decrease(float amount)
Parameters
Type | Name | Description |
---|---|---|
float | amount | The amount to remove |
Returns
Type | Description |
---|---|
float | The change made to the value, 0f if there is no change. |
DecreaseMaximum(float)
Decrease the maximum value.
Declaration
public virtual float DecreaseMaximum(float amount)
Parameters
Type | Name | Description |
---|---|---|
float | amount | The amount to remove |
Returns
Type | Description |
---|---|
float | The change made to the maximum value, 0f if there is no change. |
DecreaseMinimum(float)
Decrease the minimum value.
Declaration
public virtual float DecreaseMinimum(float amount)
Parameters
Type | Name | Description |
---|---|---|
float | amount | The amount to remove |
Returns
Type | Description |
---|---|
float | The change made to the minimum value, 0f if there is no change. |
GetClampedValue(float)
Get the clamped value within the limits.
It uses the PrecisionTolerance to return the Minimum/Maximum if the value is close enough to them.
Declaration
protected virtual float GetClampedValue(float value)
Parameters
Type | Name | Description |
---|---|---|
float | value | Value to Clamp |
Returns
Type | Description |
---|---|
float |
GetLastChangeOf(ValueType)
Return the last change made to a value.
Declaration
public float GetLastChangeOf(ValueType valueType)
Parameters
Type | Name | Description |
---|---|---|
ValueType | valueType | Which value we want to get the last change from. |
Returns
Type | Description |
---|---|
float |
Increase(float)
Increase the value.
Declaration
public virtual float Increase(float amount)
Parameters
Type | Name | Description |
---|---|---|
float | amount | The amount to add |
Returns
Type | Description |
---|---|
float | The change made to the value, 0f if there is no change. |
IncreaseMaximum(float)
Increase the maximum value.
Declaration
public virtual float IncreaseMaximum(float amount)
Parameters
Type | Name | Description |
---|---|---|
float | amount | The amount to add |
Returns
Type | Description |
---|---|
float | The change made to the maximum value, 0f if there is no change. |
IncreaseMinimum(float)
Increase the minimum value.
Declaration
public virtual float IncreaseMinimum(float amount)
Parameters
Type | Name | Description |
---|---|---|
float | amount | The amount to add |
Returns
Type | Description |
---|---|
float | The change made to the minimum value, 0f if there is no change. |
Initialize()
Set the values using the initial values and raised the InitializedEvent.
Declaration
public virtual void Initialize()
InitializeValues()
Set the Maximum, Minimum, and Value with the initial values to clamp them.
Keep the initial values in cache to reset the values at runtime if needed.
Declaration
protected virtual void InitializeValues()
OnInitialized()
Raise the InitializedEvent, we don't pass any data for the moment.
Declaration
protected virtual void OnInitialized()
OnMaximumValueReached()
Raise the MaximumValueReachedEvent and the pass the last overflow amount.
Declaration
protected virtual void OnMaximumValueReached()
OnMinimumValueReached()
Raise the MinimumValueReachedEvent and the pass the last overflow amount.
Declaration
protected virtual void OnMinimumValueReached()
OnValueChanged(float, ValueType)
Raise the ValueChangedEvent and pass all the data we have :
The new value, minimum, maximum, percentage, the difference with the previous value and the type of value that changed.
Declaration
protected virtual void OnValueChanged(float newValue, ValueType valueType)
Parameters
Type | Name | Description |
---|---|---|
float | newValue | |
ValueType | valueType |
OnValuesRestored()
Raise the ValuesRestoredEvent, pass the Value, Minimum, Maximum and Percentage.
Declaration
protected virtual void OnValuesRestored()
OnValueStateChanged()
Raise the ValueStateChangedEvent and pass the new ValueState
Declaration
protected virtual void OnValueStateChanged()
RaiseLimitReachedEvents()
Raise MaximumValueReached or MinimumValueReached depending on the new state.
Declaration
protected virtual void RaiseLimitReachedEvents()
RemoveEventsListeners()
Remove all listeners from every events, in case we need to destroy the object for example.
Declaration
public virtual void RemoveEventsListeners()
RestoreValues()
Reset the minimum, current and maximum value to their intial values.
Declaration
public virtual void RestoreValues()
SetByPercentage(float)
Set the value by passing a percentage.
For example : 20/100 (20%) => SetByPercentage(0.8) => Value will be 80/100. (80%)
Declaration
public virtual void SetByPercentage(float percentage)
Parameters
Type | Name | Description |
---|---|---|
float | percentage |
SetInitialValues(float, float, float, bool)
Set the initial values : Mnimum, Maximum, Value.
And eventually initialize.
Declaration
public virtual void SetInitialValues(float value = 100, float maximum = 100, float minimum = 0, bool initialize = false)
Parameters
Type | Name | Description |
---|---|---|
float | value | |
float | maximum | |
float | minimum | |
bool | initialize | Call Initialize() after setting the values, every values will be clamped. |
SetLastChange(float, ValueType)
Sets the last change made to a value.
Declaration
protected virtual void SetLastChange(float previousValue, ValueType valueType)
Parameters
Type | Name | Description |
---|---|---|
float | previousValue | |
ValueType | valueType |
SetLastOverflow(float)
Set the last overflow amount by removing real change made from the requested change.
The value is always positive, other script can get this value from MinimumValueReachedEvent or MaximumValueReachedEvent arguments.
Or with the LastOverflowAmount getter right after the value modification.
Declaration
protected virtual void SetLastOverflow(float requestedChange)
Parameters
Type | Name | Description |
---|---|---|
float | requestedChange |
SetMaximum(float)
Check if there is any change.
Override the maximum with the clamped new maximum.
It will clamp the value.
Then it will raised ValueChangedEvent, and check if the ValueState changed.
Declaration
protected virtual void SetMaximum(float newMaximum)
Parameters
Type | Name | Description |
---|---|---|
float | newMaximum |
SetMinimum(float)
Check if there is any change.
Override the minimum with the clamped new minimum.
It will clamp the value.
Then it will raised ValueChangedEvent, and check if the ValueState changed.
Declaration
protected virtual void SetMinimum(float newMinimum)
Parameters
Type | Name | Description |
---|---|---|
float | newMinimum |
SetToMaximum()
Set the current value to the maximum value.
Declaration
public virtual void SetToMaximum()
SetToMinimum()
Set the current value to the minimum value.
Declaration
public virtual void SetToMinimum()
SetValue(float)
Clamp the newValue, check if there is any change.
Override the value with the clamped new value.
Then it will raised ValueChangedEvent, and check if the ValueState changed.
Declaration
protected virtual void SetValue(float newValue)
Parameters
Type | Name | Description |
---|---|---|
float | newValue |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string |
UpdateValueState()
Determines if the ValueState has changed, if so it calls the OnValueStateChanged method.
Declaration
protected virtual void UpdateValueState()
Events
InitializedEvent
Declaration
public event EventHandler<ValueManagerInitializedEventArgs> InitializedEvent
Event Type
Type | Description |
---|---|
System.EventHandler<TEventArgs><ValueManagerInitializedEventArgs> |
MaximumValueReachedEvent
Declaration
public event EventHandler<MaximumValueReachedEventArgs> MaximumValueReachedEvent
Event Type
Type | Description |
---|---|
System.EventHandler<TEventArgs><MaximumValueReachedEventArgs> |
MinimumValueReachedEvent
Declaration
public event EventHandler<MinimumValueReachedEventArgs> MinimumValueReachedEvent
Event Type
Type | Description |
---|---|
System.EventHandler<TEventArgs><MinimumValueReachedEventArgs> |
ValueChangedEvent
Declaration
public event EventHandler<ValueChangedEventArgs> ValueChangedEvent
Event Type
Type | Description |
---|---|
System.EventHandler<TEventArgs><ValueChangedEventArgs> |
ValuesRestoredEvent
Declaration
public event EventHandler<ValuesRestoredEventArgs> ValuesRestoredEvent
Event Type
Type | Description |
---|---|
System.EventHandler<TEventArgs><ValuesRestoredEventArgs> |
ValueStateChangedEvent
Declaration
public event EventHandler<ValueStateEventArgs> ValueStateChangedEvent
Event Type
Type | Description |
---|---|
System.EventHandler<TEventArgs><ValueStateEventArgs> |