StateMachineBehaviour.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using UnityEngine;
  3. namespace MonsterLove.StateMachine
  4. {
  5. [RequireComponent(typeof(StateMachineEngine))]
  6. public class StateMachineBehaviour : MonoBehaviour
  7. {
  8. public StateMachineEngine stateMachine
  9. {
  10. get
  11. {
  12. if (this._stateMachine == null)
  13. {
  14. this._stateMachine = base.GetComponent<StateMachineEngine>();
  15. }
  16. if (this._stateMachine == null)
  17. {
  18. throw new Exception("Please make sure StateMachineEngine is also present on any StateMachineBehaviour objects");
  19. }
  20. return this._stateMachine;
  21. }
  22. }
  23. public void PauseStateMachine(bool isPause)
  24. {
  25. this.stateMachine.PauseStateMachine(isPause);
  26. }
  27. public Enum GetState()
  28. {
  29. return this.stateMachine.GetState();
  30. }
  31. protected void Initialize<T>()
  32. {
  33. this.stateMachine.Initialize<T>(this);
  34. }
  35. protected void ChangeState(Enum newState, object userData = null)
  36. {
  37. this.stateMachine.ChangeState(newState, userData);
  38. }
  39. private StateMachineEngine _stateMachine;
  40. }
  41. }