Table of Contents

Class StateTracker<TStateData>

Namespace
Gamelogic.Extensions
Assembly
Assembly-CSharp.dll

Tracks a number of states. Events are raised when any state is started, and when all has stopped.

public class StateTracker<TStateData>

Type Parameters

TStateData

The type of the t state data.

Inheritance
StateTracker<TStateData>
Inherited Members
Extension Methods

Remarks

A loading bar is a typical use case. The loading bar should be displayed when any of a number of load processes has started; it should be removed when all has stopped. Another use-case is keeping track of poisoning, when the poisoning can be caused by a number of poisons, and each poison is cured independently.

Constructors

StateTracker()

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

public StateTracker()

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.

Methods

StartState(TStateData)

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

public IStateToken<TStateData> StartState(TStateData stateData)

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.

Returns

IStateToken<TStateData>

A token that wraps the custom state data and can be used to stop the state started with this 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

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