Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IState
- {
- void OnEnter();
- void OnExecute();
- void OnExit();
- }
- public class StateMachine
- {
- private IState currentState;
- private IState previousState;
- // call OnUpdate in actor OnUpdate class, which is called by ActorManager which is called by GameManager xD
- // trying to make this whole thing explicit, otherwise running game logic on a different thread will be hard
- // with different thread, I mean a different CPUthread, not Coroutine
- public void OnUpdate()
- {
- if (currentState != null)
- {
- currentState.OnExecute();
- }
- }
- public void ChangeState(IState state)
- {
- if (currentState != null)
- {
- currentState.OnExit();
- }
- previousState = currentState;
- currentState = state;
- currentState.OnEnter();
- }
- public IState GetState()
- {
- return currentState;
- }
- public void RevertToPreviousState()
- {
- if (currentState != null)
- {
- currentState = previousState;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement