Class ValueRegeneration<T>
Regenerate the Value of a ValueManager every tick.
We can choose to cumulate multiple regneration type : Flat, Percentage, Percentage of Missing value.
Like the ValueManager this class doesn't know about the ProgressBar or Resource.
We use a generic type to add a layer of abstraction by given the possibility to override the ValueManager.
Inheritance
object
ValueRegeneration<T>
Assembly: cs.temp.dll.dll
Syntax
public abstract class ValueRegeneration<T> : MonoBehaviour where T : ValueManager
Type Parameters
Name |
Description |
T |
Any type that inherits from ValueManager.
|
Fields
_active
Declaration
Field Value
_calculatedValue
Declaration
protected float _calculatedValue
Field Value
_canRegenerateAtMinimumValue
Declaration
protected bool _canRegenerateAtMinimumValue
Field Value
_delayInSeconds
Declaration
protected float _delayInSeconds
Field Value
_delayTimer
Declaration
protected float _delayTimer
Field Value
_flatValue
Declaration
protected float _flatValue
Field Value
_initialized
Declaration
protected bool _initialized
Field Value
_minimumMissingPercentageValue
Declaration
protected float _minimumMissingPercentageValue
Field Value
_missingPercentageValue
Declaration
protected float _missingPercentageValue
Field Value
_percentageValue
Declaration
protected float _percentageValue
Field Value
_regenerationCondition
Declaration
protected FloatValueCondition _regenerationCondition
Field Value
Type |
Description |
FloatValueCondition |
|
_state
Declaration
protected RegenerationState _state
Field Value
_tickRate
Declaration
protected float _tickRate
Field Value
_tickRateTimer
Declaration
protected float _tickRateTimer
Field Value
_value
Declaration
Field Value
_valueManager
Declaration
protected T _valueManager
Field Value
AddFlatRegeneration
Declaration
public bool AddFlatRegeneration
Field Value
AddMissingPercentageRegeneration
Declaration
public bool AddMissingPercentageRegeneration
Field Value
AddPercentageRegeneration
Declaration
public bool AddPercentageRegeneration
Field Value
InitializedEvent
Declaration
public EventHandler<ValueRegenerationInitializedEventArgs> InitializedEvent
Field Value
RegenerationActivationChangedEvent
Declaration
public EventHandler<RegenerationActivationEventArgs> RegenerationActivationChangedEvent
Field Value
RegenerationStateChangedEvent
Declaration
public EventHandler<RegenerationStateEventArgs> RegenerationStateChangedEvent
Field Value
RegenerationValuesChangedEvent
Declaration
public EventHandler<RegenerationValuesEventArgs> RegenerationValuesChangedEvent
Field Value
RestartOnValueDecreased
Declaration
public bool RestartOnValueDecreased
Field Value
Properties
Active
Activate / Disactivate the regeneration.
Declaration
public bool Active { get; set; }
Property Value
CalculatedValue
The amount that we could regenerate with the current settings.
Declaration
public float CalculatedValue { get; }
Property Value
CanRegenerateAtMinimumValue
Allow the regeneration process to start even if the progress bar is at it's minimum value.
Declaration
public bool CanRegenerateAtMinimumValue { get; set; }
Property Value
Condition
The condition to be met to regenerate.
Declaration
public FloatValueCondition Condition { get; set; }
Property Value
Type |
Description |
FloatValueCondition |
|
DelayInSeconds
The delay in seconds before regenerating.
Declaration
public float DelayInSeconds { get; set; }
Property Value
FlatValue
The flat amount to add every tick.
Declaration
public float FlatValue { get; set; }
Property Value
Initialized
Determines if the Regeneration is listening to the ValueManager events to update it's state.
Declaration
public bool Initialized { get; protected set; }
Property Value
IsRegenerating
Returns if it's currently regenerating.
Declaration
public bool IsRegenerating { get; }
Property Value
MinimumMissingPercentageValue
The minimum amount to add to the Value Manager when using the MissingAmountPercentagePerTick.
If we are missing a small amount and use a small percentage per tick the regeneration would too much time. (If not combined with Flat / Percentage)
Declaration
public float MinimumMissingPercentageValue { get; set; }
Property Value
MissingPercentageValue
The percentage of the missing value to add every tick.
Reminder : MissingValue => _maximum - _value;
Declaration
public float MissingPercentageValue { get; set; }
Property Value
PercentageValue
The percentage of the maximum value to add every tick.
Declaration
public float PercentageValue { get; set; }
Property Value
RegenerationState
RegenerationState : Started / Regenerating / Stopped
Declaration
public RegenerationState RegenerationState { get; protected set; }
Property Value
TickRate
The time between each regeneration.
Declaration
public float TickRate { get; set; }
Property Value
Value
The current amount added every tick to the value. It's 0f if we do not regenerate.
Declaration
public float Value { get; }
Property Value
ValueManager
Reference to the Value Manager to apply the regeneration on it.
Can be overrided in subclass to pass any type that inherits from ValueManager.
Declaration
public abstract T ValueManager { get; protected set; }
Property Value
Methods
AddListeners()
Listens to ValueStateChangedEvent and ValueChangedEvent of the ValueManager
to update the regeneration state and to re-calculate the value.
Declaration
protected virtual void AddListeners()
AnyRegenerationEnable()
Determines if we have any regeneration type enable : Flat / Percentage / MissingPercentage.
Declaration
protected virtual bool AnyRegenerationEnable()
Returns
CalculateRegeneratedAmount()
Calculate the final amount to regenerate.
Declaration
protected virtual float CalculateRegeneratedAmount()
Returns
CanRegenerate()
Determines whether the regeneration process can start.
Declaration
public virtual bool CanRegenerate()
Returns
CanRegenerateAtValueState(ValueState)
Determines if the Value can be regenerated at it's current State (AtMaximum/AtMinimum/InBetween).
Declaration
protected bool CanRegenerateAtValueState(ValueState valueState)
Parameters
Returns
ConditionAllowRegeneration()
If the condition is not active it returns true, otherwise returns if the condition is met.
Declaration
protected virtual bool ConditionAllowRegeneration()
Returns
GetMissingAmountByPercentage()
Returns the percentage of the missing value.
For example with 120 / 200 HP we are missing 80 HP.
AddMissingPercentageRegeneration allows to regenerate a percentage of the 80 HP, like 10% would return 8f.
The MinimumMissingPercentageValue is there to prevent extremely low amount of regenerating for example 1% of 0.5 HP would result in 0.05f.
Declaration
protected virtual float GetMissingAmountByPercentage()
Returns
Initialize(T)
Add listeners to ValueChangedEvent and ValueStateChangedEvent from the ValueManager so
we can recalculate the regenerating amount and update the state of the regeneration.
Declaration
public virtual void Initialize(T valueManager = null)
Parameters
Type |
Name |
Description |
T |
valueManager |
|
ListenToValueManagerEvents()
Add listeners to ValueChangedEvent and ValueStateChangedEvent from the ValueManager so
we can recalculate the regenerating amount and update the state of the regeneration.
Declaration
protected virtual void ListenToValueManagerEvents()
OnInitialized()
Raise the InitializedEvent, we don't pass any data for the moment.
Declaration
protected virtual void OnInitialized()
OnValueChanged(object, ValueChangedEventArgs)
When the value of the ValueManger changed we need re-evaluate if we can still regenerate.
It also re-calculate the regenrating amount because it can be based on the missing amount of the percentage of the maximum value.
Declaration
protected virtual void OnValueChanged(object sender, ValueChangedEventArgs eventArgs)
Parameters
Regenerate()
Increment the delayTimer until it reaches the DelayInSeconds value.
Then we start the _tickRateTimer to regenerate the value every TickRate.
This will stop automatically if the ValueManager.Value reaches the Maximum or the Minimum value (Depending on CanRegenerateAtMinimumValue).
Declaration
public virtual void Regenerate()
RemoveListeners()
Stops listening to ValueStateChangedEvent and ValueChangedEvent of the ValueManager.
Declaration
protected virtual void RemoveListeners()
ResetTimers()
Set the delay and tick rate timers to 0.
Declaration
protected virtual void ResetTimers()
Restart()
Reset the regeneration process if possible by reseting all timers and setting the RegenerationgState to Started.
Declaration
StartRegeneration()
Starts the regneration process if it the state is stopped and it can regenerate.
Declaration
public void StartRegeneration()
Stop()
Stop the regeneration process and reset the timers.
Declaration
UpdateRegenerationAmount()
Whenever the maximum value of the ValueManager or the tick rate changes, the 'RegeneratedAmount' must be recalculated.
OnRegenerationValuesChanged even will be invoked passing the current regenerating amount and the new tick rate.
Declaration
protected virtual void UpdateRegenerationAmount()
UpdateRegenerationState(object, ValueStateEventArgs)
Stop or Start the regeneration process depending on the state of the value : AtMinimum, AtMaximum, InBetween.
Declaration
protected virtual void UpdateRegenerationState(object sender, ValueStateEventArgs eventArgs)
Parameters