NormalExistSafetyAreaSpecialState.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// 普通状态
  6. /// </summary>
  7. public class NormalExistSafetyAreaSpecialState : AbstractExistSafetyAreaSpecialState<SafetyAreaBase>
  8. {
  9. private const float OFFLINE_MAP_CALL_TIME_SPAN = 0.5f;
  10. private const float AUTO_SAVE_MAP_TIME_SPAN = 60f;
  11. private const float TAP_TIMER = 0.5f;
  12. private float timer = 0f;
  13. private bool isOpenSeeThrough = false;
  14. private float savemapTimer = 0f;
  15. private int tapCount;
  16. private float tapTimer = 0f;
  17. public override void OnStateBreathe()
  18. {
  19. if (SafetyAreaManager.Instance.isSettingSafetyArea || SafetyAreaManager.Instance.isDisableSafetyArea)
  20. {
  21. reference.outOfSafetyArea.SetActive(false);
  22. reference.nomapUI.SetActive(false);
  23. reference.slamLostUI.gameObject.SetActive(false);
  24. reference.meshRenderer.enabled = !SafetyAreaManager.Instance.isDisableSafetyArea;
  25. return;
  26. }
  27. if (tapTimer > 0f)
  28. {
  29. tapTimer -= Time.deltaTime;
  30. }
  31. else
  32. {
  33. tapTimer = 0f;
  34. }
  35. timer += Time.deltaTime;
  36. savemapTimer += Time.deltaTime;
  37. if (savemapTimer > AUTO_SAVE_MAP_TIME_SPAN)
  38. {
  39. savemapTimer = 0f;
  40. API_GSXR_Slam.GSXR_SaveMap();
  41. }
  42. if (timer >= OFFLINE_MAP_CALL_TIME_SPAN)
  43. {
  44. timer = 0f;
  45. int currentRelocState = API_GSXR_Slam.GSXR_Get_OfflineMapRelocState();
  46. if (currentRelocState == 0)
  47. {
  48. reference.ChangeState(ExistSafetyAreaEnum.NoMap);
  49. return;
  50. }
  51. }
  52. if (reference.distance > 10f)
  53. {
  54. reference.ChangeState(ExistSafetyAreaEnum.SlamLost);
  55. return;
  56. }
  57. if (reference.alpha >= 1.1f)
  58. {
  59. reference.ChangeState(ExistSafetyAreaEnum.OutOfArea);
  60. return;
  61. }
  62. }
  63. public override void OnStateEnter(object data)
  64. {
  65. timer = 0f;
  66. savemapTimer = 0f;
  67. isOpenSeeThrough = false;
  68. SafetyAreaManager.Instance.OnDisableSafetyArea += OnDisableChange;
  69. SafetyAreaManager.Instance.OnDoubleTapShowSafetyArea += OnDoubleTapShowSafetyArea;
  70. API_GSXR_Slam.GSXR_Add_SlamPauseCallback(OnSlamPause);
  71. if (!SafetyAreaManager.Instance.isSettingSafetyArea)
  72. {
  73. SafetyAreaManager.Instance.EnterSafetyAreaInvoke();
  74. }
  75. #if !UNITY_EDITOR
  76. TpActionManager.Instance.ActiveTpListener(OnTpDown);
  77. #endif
  78. }
  79. public override void OnStateExit(object data)
  80. {
  81. #if !UNITY_EDITOR
  82. TpActionManager.Instance.CancelTpListener();
  83. #endif
  84. API_GSXR_Slam.GSXR_Remove_SlamPauseCallback(OnSlamPause);
  85. SafetyAreaManager.Instance.OnDoubleTapShowSafetyArea -= OnDoubleTapShowSafetyArea;
  86. SafetyAreaManager.Instance.OnDisableSafetyArea -= OnDisableChange;
  87. }
  88. private void OnSlamPause(bool isPause)
  89. {
  90. if (!isPause && !SafetyAreaManager.Instance.isDisableSafetyArea)
  91. {
  92. if (isOpenSeeThrough)
  93. {
  94. API_GSXR_Slam.GSXR_StartSeeThrough();
  95. }
  96. }
  97. }
  98. private void OnDisableChange(bool isDisable)
  99. {
  100. if (!isDisable && isOpenSeeThrough)
  101. {
  102. API_GSXR_Slam.GSXR_StartSeeThrough();
  103. }
  104. else
  105. {
  106. API_GSXR_Slam.GSXR_StopSeeThrough();
  107. }
  108. }
  109. private void OnDoubleTapShowSafetyArea(bool isActive)
  110. {
  111. if (!isActive)
  112. {
  113. isOpenSeeThrough = false;
  114. API_GSXR_Slam.GSXR_StopSeeThrough();
  115. }
  116. }
  117. private void OnTpDown()
  118. {
  119. if (!SafetyAreaManager.Instance.DoubleClickShowSeeThrough || SafetyAreaManager.Instance.isSettingSafetyArea || SafetyAreaManager.Instance.isDisableSafetyArea)
  120. {
  121. return;
  122. }
  123. if (tapTimer != 0f)
  124. {
  125. if (isOpenSeeThrough)
  126. {
  127. //Debug.LogError("LQR GSXR_StopSeeThrough");
  128. isOpenSeeThrough = false;
  129. API_GSXR_Slam.GSXR_StopSeeThrough();
  130. }
  131. else
  132. {
  133. //Debug.LogError("LQR GSXR_StartSeeThrough");
  134. isOpenSeeThrough = true;
  135. API_GSXR_Slam.GSXR_StartSeeThrough();
  136. }
  137. tapTimer = 0f;
  138. }
  139. else
  140. {
  141. tapTimer = TAP_TIMER;
  142. }
  143. }
  144. }