StationaryAreaStep.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class StationaryAreaStep : AbstractSafetyAreaStep<SafetyAreaMono>
  5. {
  6. public StationaryAreaStep(SafetyAreaMono safetyAreaMono) : base(safetyAreaMono)
  7. {
  8. }
  9. public override void OnEnterStep(object data)
  10. {
  11. //reference.safetyGreyCameraUI.gameObject.SetActive(true);
  12. reference.stationaryAreaUI.gameObject.SetActive(true);
  13. reference.stationaryAreaUI.Init();
  14. reference.stationaryAreaUI.OnSwitchToPlayAreaClick += OnSwitchPlayAreaClick;
  15. reference.stationaryAreaUI.OnCancelClick += OnStationaryAreaCancelClick;
  16. reference.stationaryAreaUI.OnConfirmClick += OnStationaryAreaConfirmClick;
  17. SafetyAreaManager.Instance.CreateStationarySafetyArea();
  18. UnFreezeStationarySafetyArea();
  19. HidePlane();
  20. SafetyAreaManager.Instance.stationaryAreaMono.SetMaterial(reference.areaConfirmMat);
  21. }
  22. public override void OnExitStep()
  23. {
  24. reference.stationaryAreaUI.OnSwitchToPlayAreaClick -= OnSwitchPlayAreaClick;
  25. reference.stationaryAreaUI.OnCancelClick -= OnStationaryAreaCancelClick;
  26. reference.stationaryAreaUI.OnConfirmClick -= OnStationaryAreaConfirmClick;
  27. reference.stationaryAreaUI.Release();
  28. reference.stationaryAreaUI.gameObject.SetActive(false);
  29. //reference.safetyGreyCameraUI.gameObject.SetActive(false);
  30. }
  31. public override SafetyAreaStepEnum GetStepEnum()
  32. {
  33. return SafetyAreaStepEnum.StationaryArea;
  34. }
  35. //暂时隐藏平面
  36. public void HidePlane()
  37. {
  38. reference.safetyPlaneMono.gameObject.SetActive(false);
  39. }
  40. public void OnSwitchPlayAreaClick()
  41. {
  42. SafetyAreaManager.Instance.DestroyStationaryArea();
  43. SafetyAreaManager.Instance.ChangeStep(SafetyAreaStepEnum.PlayArea);
  44. SafetyAreaManager.Instance.GetStep<PlayAreaStep>(SafetyAreaStepEnum.PlayArea).ChangePlanePosition();
  45. }
  46. private void OnStationaryAreaCancelClick()
  47. {
  48. SafetyAreaManager.Instance.DestroyStationaryArea();
  49. reference.DestroySafetyPlane();
  50. SafetyAreaManager.Instance.ExitSafeAreaStep();
  51. }
  52. private void OnStationaryAreaConfirmClick()
  53. {
  54. SafetyAreaManager.Instance.stationaryAreaMono.SetMaterial(reference.areaNormalMat);
  55. FreezeStationarySafetyArea();
  56. reference.DestroySafetyPlane();
  57. SafetyAreaManager.Instance.ExitSafeAreaStep();
  58. }
  59. public void FreezeStationarySafetyArea()
  60. {
  61. if (SafetyAreaManager.Instance.stationaryAreaMono == null)
  62. {
  63. Debug.LogError("stationaryAreaMono is Null FreezeStationarySafetyArea");
  64. }
  65. SafetyAreaManager.Instance.stationaryAreaMono.FreezeStationaryAreaPosition();
  66. }
  67. public void UnFreezeStationarySafetyArea()
  68. {
  69. if (SafetyAreaManager.Instance.stationaryAreaMono == null)
  70. {
  71. Debug.LogError("stationaryAreaMono is Null UnFreezeStationarySafetyArea");
  72. }
  73. SafetyAreaManager.Instance.stationaryAreaMono.UnFreezeStationaryAreaPosition();
  74. }
  75. private Vector2 circleCenter = new Vector2(0, 0);
  76. public void SetCircleCenter(Vector3 headPosition)
  77. {
  78. circleCenter = new Vector2(headPosition.x, headPosition.z);
  79. }
  80. public Vector2 GetCircleCenter()
  81. {
  82. return circleCenter;
  83. }
  84. public override void OnUserCancel()
  85. {
  86. OnStationaryAreaConfirmClick();
  87. }
  88. }