Search Results for

    Show / Hide Table of Contents

    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>
    Regeneration
    ResourceRegeneration
    Namespace: TetraCreations.ProgressBarSystem
    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
    protected bool _active
    Field Value
    Type Description
    bool

    _calculatedValue

    Declaration
    protected float _calculatedValue
    Field Value
    Type Description
    float

    _canRegenerateAtMinimumValue

    Declaration
    protected bool _canRegenerateAtMinimumValue
    Field Value
    Type Description
    bool

    _delayInSeconds

    Declaration
    protected float _delayInSeconds
    Field Value
    Type Description
    float

    _delayTimer

    Declaration
    protected float _delayTimer
    Field Value
    Type Description
    float

    _flatValue

    Declaration
    protected float _flatValue
    Field Value
    Type Description
    float

    _initialized

    Declaration
    protected bool _initialized
    Field Value
    Type Description
    bool

    _minimumMissingPercentageValue

    Declaration
    protected float _minimumMissingPercentageValue
    Field Value
    Type Description
    float

    _missingPercentageValue

    Declaration
    protected float _missingPercentageValue
    Field Value
    Type Description
    float

    _percentageValue

    Declaration
    protected float _percentageValue
    Field Value
    Type Description
    float

    _regenerationCondition

    Declaration
    protected FloatValueCondition _regenerationCondition
    Field Value
    Type Description
    FloatValueCondition

    _state

    Declaration
    protected RegenerationState _state
    Field Value
    Type Description
    RegenerationState

    _tickRate

    Declaration
    protected float _tickRate
    Field Value
    Type Description
    float

    _tickRateTimer

    Declaration
    protected float _tickRateTimer
    Field Value
    Type Description
    float

    _value

    Declaration
    protected float _value
    Field Value
    Type Description
    float

    _valueManager

    Declaration
    protected T _valueManager
    Field Value
    Type Description
    T

    AddFlatRegeneration

    Declaration
    public bool AddFlatRegeneration
    Field Value
    Type Description
    bool

    AddMissingPercentageRegeneration

    Declaration
    public bool AddMissingPercentageRegeneration
    Field Value
    Type Description
    bool

    AddPercentageRegeneration

    Declaration
    public bool AddPercentageRegeneration
    Field Value
    Type Description
    bool

    InitializedEvent

    Declaration
    public EventHandler<ValueRegenerationInitializedEventArgs> InitializedEvent
    Field Value
    Type Description
    System.EventHandler<TEventArgs><ValueRegenerationInitializedEventArgs>

    RegenerationActivationChangedEvent

    Declaration
    public EventHandler<RegenerationActivationEventArgs> RegenerationActivationChangedEvent
    Field Value
    Type Description
    System.EventHandler<TEventArgs><RegenerationActivationEventArgs>

    RegenerationStateChangedEvent

    Declaration
    public EventHandler<RegenerationStateEventArgs> RegenerationStateChangedEvent
    Field Value
    Type Description
    System.EventHandler<TEventArgs><RegenerationStateEventArgs>

    RegenerationValuesChangedEvent

    Declaration
    public EventHandler<RegenerationValuesEventArgs> RegenerationValuesChangedEvent
    Field Value
    Type Description
    System.EventHandler<TEventArgs><RegenerationValuesEventArgs>

    RestartOnValueDecreased

    Declaration
    public bool RestartOnValueDecreased
    Field Value
    Type Description
    bool

    Properties

    Active

    Activate / Disactivate the regeneration.

    Declaration
    public bool Active { get; set; }
    Property Value
    Type Description
    bool

    CalculatedValue

    The amount that we could regenerate with the current settings.

    Declaration
    public float CalculatedValue { get; }
    Property Value
    Type Description
    float

    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
    Type Description
    bool

    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
    Type Description
    float

    FlatValue

    The flat amount to add every tick.

    Declaration
    public float FlatValue { get; set; }
    Property Value
    Type Description
    float

    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
    Type Description
    bool

    IsRegenerating

    Returns if it's currently regenerating.

    Declaration
    public bool IsRegenerating { get; }
    Property Value
    Type Description
    bool

    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
    Type Description
    float

    MissingPercentageValue

    The percentage of the missing value to add every tick.
    Reminder : MissingValue => _maximum - _value;

    Declaration
    public float MissingPercentageValue { get; set; }
    Property Value
    Type Description
    float

    PercentageValue

    The percentage of the maximum value to add every tick.

    Declaration
    public float PercentageValue { get; set; }
    Property Value
    Type Description
    float

    RegenerationState

    RegenerationState : Started / Regenerating / Stopped

    Declaration
    public RegenerationState RegenerationState { get; protected set; }
    Property Value
    Type Description
    RegenerationState

    TickRate

    The time between each regeneration.

    Declaration
    public float TickRate { get; set; }
    Property Value
    Type Description
    float

    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
    Type Description
    float

    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
    Type Description
    T

    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
    Type Description
    bool

    CalculateRegeneratedAmount()

    Calculate the final amount to regenerate.

    Declaration
    protected virtual float CalculateRegeneratedAmount()
    Returns
    Type Description
    float

    CanRegenerate()

    Determines whether the regeneration process can start.

    Declaration
    public virtual bool CanRegenerate()
    Returns
    Type Description
    bool

    CanRegenerateAtValueState(ValueState)

    Determines if the Value can be regenerated at it's current State (AtMaximum/AtMinimum/InBetween).

    Declaration
    protected bool CanRegenerateAtValueState(ValueState valueState)
    Parameters
    Type Name Description
    ValueState valueState
    Returns
    Type Description
    bool

    ConditionAllowRegeneration()

    If the condition is not active it returns true, otherwise returns if the condition is met.

    Declaration
    protected virtual bool ConditionAllowRegeneration()
    Returns
    Type Description
    bool

    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
    Type Description
    float

    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
    Type Name Description
    object sender
    ValueChangedEventArgs eventArgs

    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
    public void Restart()

    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
    public void Stop()

    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
    Type Name Description
    object sender
    ValueStateEventArgs eventArgs
    In This Article
    Back to top Tetra Creations documentation