PrepareDrawPlayAreaState.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. public class PrepareDrawPlayAreaState : AbstractPlayAreaState<SafetyAreaMono>
  6. {
  7. private PlayAreaStep playAreaStep;
  8. public override void OnStateEnter(object data)
  9. {
  10. if (playAreaStep == null)
  11. {
  12. playAreaStep = SafetyAreaManager.Instance.GetStep<PlayAreaStep>(SafetyAreaStepEnum.PlayArea);
  13. }
  14. reference.safetyPlaneMono.RegistPointerDownFillEvent();
  15. reference.safetyPlaneMono.RegistPointerUpFillEvent();
  16. ShowPlayAreaWaitingDrawUI();
  17. reference.safetyPlaneMono.RegistPointerUpEvent(FillIndices);
  18. reference.playAreaWaitingDrawUI.OnSwitchToStationaryAreaClick += SwitchToStationaryAreaStep;
  19. reference.playAreaWaitingDrawUI.OnBackClick += SwitchToGroundHeightStep;
  20. }
  21. public override void OnStateExit(object data)
  22. {
  23. reference.playAreaWaitingDrawUI.OnSwitchToStationaryAreaClick -= SwitchToStationaryAreaStep;
  24. reference.playAreaWaitingDrawUI.OnBackClick -= SwitchToGroundHeightStep;
  25. reference.safetyPlaneMono.UnRegistPointerUpEvent(FillIndices);
  26. HidePlayAreaWaitingDrawUI();
  27. //HidePlane();
  28. if (reference.safetyPlaneMono != null)
  29. {
  30. reference.safetyPlaneMono.UnRegistPointerDownFillEvent();
  31. reference.safetyPlaneMono.UnRegistPointerUpFillEvent();
  32. }
  33. }
  34. public override void OnStateBreathe()
  35. {
  36. }
  37. private void SwitchToStationaryAreaStep()
  38. {
  39. SafetyAreaManager.Instance.ChangeStep(SafetyAreaStepEnum.StationaryArea);
  40. }
  41. private void SwitchToGroundHeightStep()
  42. {
  43. SafetyAreaManager.Instance.ChangeStep(SafetyAreaStepEnum.GroundHeight);
  44. }
  45. public void ShowPlayAreaWaitingDrawUI()
  46. {
  47. reference.playAreaWaitingDrawUI.gameObject.SetActive(true);
  48. reference.playAreaWaitingDrawUI.Init();
  49. }
  50. public void HidePlayAreaWaitingDrawUI()
  51. {
  52. reference.playAreaWaitingDrawUI.Release();
  53. reference.playAreaWaitingDrawUI.gameObject.SetActive(false);
  54. }
  55. private void FillIndices(PointerEventData pointerEventData)
  56. {
  57. reference.safetyPlaneMono.FillIndices();
  58. if (reference.safetyPlaneMono.CheckIndicesEnough())
  59. {
  60. playAreaStep.ChangePlayAreaState(PlayAreaStateEnum.OK);
  61. }
  62. else
  63. {
  64. playAreaStep.ChangePlayAreaState(PlayAreaStateEnum.NotEnough);
  65. }
  66. }
  67. }