OutOfExistSafetyAreaSpecialState.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class OutOfExistSafetyAreaSpecialState : AbstractExistSafetyAreaSpecialState<SafetyAreaBase>
  5. {
  6. private const float OFFLINE_MAP_CALL_TIME_SPAN = 0.5f;
  7. private float timer = 0f;
  8. public override void OnStateBreathe()
  9. {
  10. if (SafetyAreaManager.Instance.isSettingSafetyArea || SafetyAreaManager.Instance.isDisableSafetyArea)
  11. {
  12. reference.outOfSafetyArea.SetActive(false);
  13. reference.nomapUI.SetActive(false);
  14. reference.slamLostUI.gameObject.SetActive(false);
  15. reference.meshRenderer.enabled = !SafetyAreaManager.Instance.isDisableSafetyArea;
  16. return;
  17. }
  18. reference.outOfSafetyArea.SetActive(true);
  19. reference.meshRenderer.enabled = true;
  20. timer += Time.deltaTime;
  21. if (timer >= OFFLINE_MAP_CALL_TIME_SPAN)
  22. {
  23. timer = 0f;
  24. int currentRelocState = API_GSXR_Slam.GSXR_Get_OfflineMapRelocState();
  25. if (currentRelocState == 0)
  26. {
  27. reference.ChangeState(ExistSafetyAreaEnum.NoMap);
  28. return;
  29. }
  30. }
  31. if (reference.distance > 10f)
  32. {
  33. reference.ChangeState(ExistSafetyAreaEnum.SlamLost);
  34. return;
  35. }
  36. if (reference.alpha < 1.1f)
  37. {
  38. reference.ChangeState(ExistSafetyAreaEnum.Normal);
  39. return;
  40. }
  41. }
  42. public override void OnStateEnter(object data)
  43. {
  44. SafetyAreaManager.Instance.ExitSafetyAreaInvoke();//OnEnterSafetyArea?.Invoke();
  45. SafetyAreaManager.Instance.OnDisableSafetyArea += OnDisableChange;
  46. if (!SafetyAreaManager.Instance.isDisableSafetyArea)
  47. {
  48. API_GSXR_Slam.GSXR_StartSeeThrough();
  49. }
  50. API_GSXR_Slam.GSXR_Add_SlamPauseCallback(OnSlamPause);
  51. }
  52. public override void OnStateExit(object data)
  53. {
  54. API_GSXR_Slam.GSXR_Remove_SlamPauseCallback(OnSlamPause);
  55. API_GSXR_Slam.GSXR_StopSeeThrough();
  56. reference.outOfSafetyArea.SetActive(false);
  57. SafetyAreaManager.Instance.OnDisableSafetyArea -= OnDisableChange;
  58. //SafetyAreaManager.Instance.EnterSafetyAreaInvoke();//OnExitSafetyArea?.Invoke();
  59. }
  60. private void OnSlamPause(bool isPause)
  61. {
  62. if (!isPause && !SafetyAreaManager.Instance.isDisableSafetyArea)
  63. {
  64. API_GSXR_Slam.GSXR_StartSeeThrough();
  65. }
  66. }
  67. private void OnDisableChange(bool isDisable)
  68. {
  69. if (!isDisable)
  70. {
  71. API_GSXR_Slam.GSXR_StartSeeThrough();
  72. }
  73. else
  74. {
  75. API_GSXR_Slam.GSXR_StopSeeThrough();
  76. }
  77. }
  78. }