// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
namespace FlaxEngine.Utilities
{
///
/// State machine state
///
public abstract class State
{
internal StateMachine owner;
///
/// Gets the state machine.
///
public StateMachine StateMachine => owner;
///
/// Gets a value indicating whether this state is active.
///
public bool IsActive => owner != null && owner.CurrentState == this;
///
/// Checks if can enter to that state
///
/// True if can enter to that state, otherwise false
public virtual bool CanEnter()
{
return true;
}
///
/// Checks if can exit from that state
///
/// Next state to enter after exit from the current state
/// True if can exit from that state, otherwise false
public virtual bool CanExit(State nextState)
{
return true;
}
///
/// Called when state is starting to be active.
///
public virtual void OnEnter()
{
}
///
/// Called when state is ending to be active.
///
/// The next state.
public virtual void OnExit(State nextState)
{
}
///
public override string ToString()
{
return GetType().Name;
}
}
}