Skip to main content

StateTransition<TFrom, TTo>

An abstract class in Root.Township, Alta.PlayerStates.Transitions.

Base for a rule that moves a player from one player state to another. Subclasses hook up listeners while the transition is active and call TransitionToDestinationState when their condition is met.

Constructors​

MemberWhat it is
protected StateTransition(PlayerStateType destinationStateType)Creates a StateTransition from destinationStateType.

Fields​

MemberWhat it is
protected static Logger loggerShared logger for transitions.
2 private and internal fields
MemberWhat it is
private bool isActiveBacking field for IsActive.
private IPlayerState sourceStateBacking field for SourceState.

Properties​

MemberWhat it is
PlayerStateType DestinationStateType { get; }The state type this transition leads to.
IPlayerState SourceState { get; }The state this transition belongs to.
IStateTransitionsManager StateTransitionsManager { get; set; }Manager used to switch states.
protected Player Player { get; private set; }The player whose state this is, taken from the source state.
protected PlayerController PlayerController { get; private set; }The player's controller. Filled in later if the player had none when the source state was set.
protected PlayerStateManager StateManager { get; private set; }The player's state manager, taken from the source state.
2 private and internal properties
MemberWhat it is
private bool Alta.PlayerStates.Transitions.IPlayerStateTransition.IsActive { get; set; }Turning it on calls AddListeners, off calls RemoveListeners. Setting the same value again only logs a warning.
private IPlayerState Alta.PlayerStates.Transitions.IPlayerStateTransition.SourceState { set; }Sets the source state and picks up its state manager, player and player controller (waiting for the controller if it isn't set yet).

Methods​

MemberWhat it is
protected abstract void AddListeners()Called when the transition becomes active; subscribe to whatever triggers it here.
protected virtual void DestinationPreActivationCallback(IPlayerState activatedState)Called on the new state just before it activates. Does nothing by default.
protected void OnTransitionComplete(IPlayerState transitionedState)Called after the switch with the new current state. Empty.
protected abstract void RemoveListeners()Called when the transition becomes inactive; undo AddListeners here.
protected virtual IPlayerState TransitionToDestinationState()Switches the player to the destination state and returns it.
3 private and internal methods
MemberWhat it is
private void Alta.PlayerStates.Transitions.IPlayerStateTransition.Clear()Clears the source state.
private void Alta.PlayerStates.Transitions.IPlayerStateTransition.TransitionToDestinationStateExternal()Runs the transition from outside; used by the transitions manager's TriggerTransition.
private void UpdatePlayerController(Player player, PlayerController playerController)Picks up the player controller once the player gets one, then unhooks.