Table of Contents

Class TimedStateTracker<TStateData>

Namespace
Gamelogic.Extensions
Assembly
Assembly-CSharp.dll

The same as StateTracker, but states can also time out.

public class TimedStateTracker<TStateData>

Type Parameters

TStateData

The type of the t state data.

Inheritance
TimedStateTracker<TStateData>
Inherited Members
Extension Methods

Remarks

Time-outs are managed by this class: when the state times out, it is stopped, and an event is raised. This tracker must be updated (typically in a mono-behaviour Update method).

Constructors

TimedStateTracker()

Initializes a new instance of the TimedStateTracker<TStateData> class.

public TimedStateTracker()

Properties

ActiveTokens

Returns all the active tokens: tokens returned when states has been started that has not yet been stopped.

public IEnumerable<IStateToken<TStateData>> ActiveTokens { get; }

Property Value

IEnumerable<IStateToken<TStateData>>

The active tokens.

IsActive

Gets a value indicating whether this tracker is active, that is, whether any state has been started that has not been stopped.

public bool IsActive { get; }

Property Value

bool

true if this tracker is active; otherwise, false.

IsPaused

Gets a value indicating whether this tracker is paused.

public bool IsPaused { get; }

Property Value

bool

true if this tracker is paused; otherwise, false.

Methods

Pause()

Pauses this tracker.

public void Pause()

Remarks

When paused, the time for timeouts is not advanced.

StartState(TStateData, float)

Starts a state, and returns a token that can be used to stop it again.

public IStateToken<TStateData> StartState(TStateData stateData, float maxTime)

Parameters

stateData TStateData

Custom state data. This is useful in cases where all the active states needs to be examined. For example, this data can be used to identify states externally.

maxTime float

The maximum amount of time this state should survive past the current time.

Returns

IStateToken<TStateData>

A token that wraps the custom state data and can be used to stop the state started with this method.

Remarks

For a state to time out, it is necessary for the Update method to be called regularly (for example, in a MonoBehaviours Update method).

StartState(TStateData, float, Action)

Starts a state, and returns a token that can be used to stop it again.

public IStateToken<TStateData> StartState(TStateData stateData, float maxTime, Action onTimeOut)

Parameters

stateData TStateData

Custom state data. This is useful in cases where all the active states needs to be examined. For example, this data can be used to identify states externally.

maxTime float

The maximum amount of time this state should survive past the current time.

onTimeOut Action

The action to perform when timing out.

Returns

IStateToken<TStateData>

A token that wraps the custom state data and can be used to stop the state started with this method.

Remarks

For a state to time out, it is necessary for the Update method to be called regularly (for example, in a MonoBehaviours Update method).

StopState(IStateToken<TStateData>)

Stops the state associated with the token. The token must be one that was returned when the state was started.

public void StopState(IStateToken<TStateData> token)

Parameters

token IStateToken<TStateData>

The token of the state to stop.

Exceptions

ArgumentNullException

token

InvalidOperationException

The given token is not from this state tracker or the given token is not active

Unpause()

Unpauses this tracker.

public void Unpause()

Update(float)

Updates this tracker with the specified current time.

public void Update(float deltaTime)

Parameters

deltaTime float

The current delta time.

Events

OnStateActive

Occurs when this tracker is inactive and a state is started (so that this tracker becomes active).

public event Action OnStateActive

Event Type

Action

OnStateInactive

Occurs when all active states are stopped, that is, when this tracker is active and becomes inactive.

public event Action OnStateInactive

Event Type

Action