PlayAreaNotEnoughState.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. public class PlayAreaNotEnoughState : 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. ShowPlayAreaNotEnoughUI();
  17. reference.playAreaNotEnoughUI.OnRedrawAreaClick += ChangePrepareDrawPlayAreaState;
  18. reference.playAreaNotEnoughUI.OnBackClick += ChangePrepareDrawPlayAreaState;
  19. reference.playAreaNotEnoughUI.OnSwitchToStationaryAreaClick += SwitchToStationaryAreaStep;
  20. //FillIndices(null);
  21. reference.safetyPlaneMono.RegistPointerUpEvent(FillIndices);
  22. }
  23. public override void OnStateExit(object data)
  24. {
  25. reference.safetyPlaneMono.UnRegistPointerUpEvent(FillIndices);
  26. reference.playAreaNotEnoughUI.OnRedrawAreaClick -= ChangePrepareDrawPlayAreaState;
  27. reference.playAreaNotEnoughUI.OnBackClick -= ChangePrepareDrawPlayAreaState;
  28. reference.playAreaNotEnoughUI.OnSwitchToStationaryAreaClick -= SwitchToStationaryAreaStep;
  29. HidePlayAreaNotEnougUI();
  30. HidePlayAreaNotEnougUI();
  31. if (reference.safetyPlaneMono != null)
  32. {
  33. reference.safetyPlaneMono.UnRegistPointerDownFillEvent();
  34. reference.safetyPlaneMono.UnRegistPointerUpFillEvent();
  35. }
  36. }
  37. public override void OnStateBreathe()
  38. {
  39. }
  40. private void FillIndices(PointerEventData pointerEventData)
  41. {
  42. reference.safetyPlaneMono.FillIndices();
  43. if (reference.safetyPlaneMono.CheckIndicesEnough())
  44. {
  45. playAreaStep.ChangePlayAreaState(PlayAreaStateEnum.OK);
  46. }
  47. }
  48. private void SwitchToStationaryAreaStep()
  49. {
  50. SafetyAreaManager.Instance.ChangeStep(SafetyAreaStepEnum.StationaryArea);
  51. }
  52. private void ChangePrepareDrawPlayAreaState()
  53. {
  54. reference.safetyPlaneMono.ClearAllMeshColor();
  55. playAreaStep.ChangePlayAreaState(PlayAreaStateEnum.WaitingDraw);
  56. }
  57. private void ShowPlayAreaNotEnoughUI()
  58. {
  59. reference.playAreaNotEnoughUI.gameObject.SetActive(true);
  60. reference.playAreaNotEnoughUI.Init();
  61. }
  62. private void HidePlayAreaNotEnougUI()
  63. {
  64. reference.playAreaNotEnoughUI.Release();
  65. reference.playAreaNotEnoughUI.gameObject.SetActive(false);
  66. }
  67. }