You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

77 lines
1.0 KiB

  1. using System;
  2. using UnityEngine;
  3. public class State : MonoBehaviour
  4. {
  5. public FiniteStateMachine fsm
  6. {
  7. get
  8. {
  9. return this._fsm;
  10. }
  11. set
  12. {
  13. this._fsm = value;
  14. }
  15. }
  16. public virtual void Init()
  17. {
  18. this.View.Init();
  19. }
  20. public virtual void Enter(State oldState, bool openView)
  21. {
  22. this._isInState = true;
  23. if (openView)
  24. {
  25. this.View.Open(oldState);
  26. }
  27. }
  28. public virtual void Enter(State oldState)
  29. {
  30. this.Enter(oldState, true);
  31. }
  32. public virtual void Leave(State newState, bool closeView)
  33. {
  34. this._isInState = false;
  35. if (closeView)
  36. {
  37. this.View.Close(newState);
  38. }
  39. }
  40. public virtual void Leave(State newState)
  41. {
  42. this.Leave(newState, true);
  43. }
  44. private void Update()
  45. {
  46. if (this._isInState)
  47. {
  48. this.OnUpdate();
  49. }
  50. }
  51. protected virtual void OnUpdate()
  52. {
  53. }
  54. public virtual bool IsHUDState
  55. {
  56. get
  57. {
  58. return false;
  59. }
  60. }
  61. public GUIView View;
  62. protected FiniteStateMachine _fsm;
  63. protected bool _isInState;
  64. }