ExistSafetyAreaStateMachine.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public enum ExistSafetyAreaEnum
  5. {
  6. Normal,
  7. OutOfArea,
  8. NoMap,
  9. SlamLost
  10. }
  11. public class ExistSafetyAreaStateMachine
  12. {
  13. public Dictionary<ExistSafetyAreaEnum, AbstractExistSafetyAreaSpecialState<SafetyAreaBase>> playAreaStateDic;
  14. private IState currentState;
  15. public void InitStateMachine(SafetyAreaBase safetyAreaBase)
  16. {
  17. if (playAreaStateDic == null)
  18. {
  19. playAreaStateDic = new Dictionary<ExistSafetyAreaEnum, AbstractExistSafetyAreaSpecialState<SafetyAreaBase>>();
  20. playAreaStateDic.Add(ExistSafetyAreaEnum.Normal, new NormalExistSafetyAreaSpecialState());
  21. playAreaStateDic.Add(ExistSafetyAreaEnum.OutOfArea, new OutOfExistSafetyAreaSpecialState());
  22. playAreaStateDic.Add(ExistSafetyAreaEnum.NoMap, new NoMapExistSafetyAreaSpecialState());
  23. playAreaStateDic.Add(ExistSafetyAreaEnum.SlamLost, new SlamLostExistSafetyAreaSpecialState());
  24. foreach (AbstractExistSafetyAreaSpecialState<SafetyAreaBase> valueItem in playAreaStateDic.Values)
  25. {
  26. valueItem.Init(safetyAreaBase);
  27. }
  28. }
  29. }
  30. public void ChangeState(ExistSafetyAreaEnum existSafetyAreaEnum, object data = null)
  31. {
  32. if (currentState != null)
  33. {
  34. currentState.OnStateExit(data);
  35. }
  36. IState newState = playAreaStateDic[existSafetyAreaEnum];
  37. newState.OnStateEnter(data);
  38. currentState = newState;
  39. }
  40. public void ExitCurrentState(object data = null)
  41. {
  42. if (currentState != null)
  43. {
  44. currentState.OnStateExit(data);
  45. }
  46. currentState = null;
  47. }
  48. public void Breathe()
  49. {
  50. if (currentState != null)
  51. {
  52. currentState.OnStateBreathe();
  53. }
  54. }
  55. }