123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- /// <summary>
- /// 普通状态
- /// </summary>
- public class NormalExistSafetyAreaSpecialState : AbstractExistSafetyAreaSpecialState<SafetyAreaBase>
- {
- private const float OFFLINE_MAP_CALL_TIME_SPAN = 0.5f;
- private const float AUTO_SAVE_MAP_TIME_SPAN = 60f;
- private const float TAP_TIMER = 0.5f;
- private float timer = 0f;
- private bool isOpenSeeThrough = false;
- private float savemapTimer = 0f;
- private int tapCount;
- private float tapTimer = 0f;
-
- public override void OnStateBreathe()
- {
- if (SafetyAreaManager.Instance.isSettingSafetyArea || SafetyAreaManager.Instance.isDisableSafetyArea)
- {
- reference.outOfSafetyArea.SetActive(false);
- reference.nomapUI.SetActive(false);
- reference.slamLostUI.gameObject.SetActive(false);
- reference.meshRenderer.enabled = !SafetyAreaManager.Instance.isDisableSafetyArea;
- return;
- }
- if (tapTimer > 0f)
- {
- tapTimer -= Time.deltaTime;
- }
- else
- {
- tapTimer = 0f;
- }
- timer += Time.deltaTime;
- savemapTimer += Time.deltaTime;
- if (savemapTimer > AUTO_SAVE_MAP_TIME_SPAN)
- {
- savemapTimer = 0f;
- API_GSXR_Slam.GSXR_SaveMap();
- }
- if (timer >= OFFLINE_MAP_CALL_TIME_SPAN)
- {
- timer = 0f;
- int currentRelocState = API_GSXR_Slam.GSXR_Get_OfflineMapRelocState();
- if (currentRelocState == 0)
- {
- reference.ChangeState(ExistSafetyAreaEnum.NoMap);
- return;
- }
- }
- if (reference.distance > 10f)
- {
- reference.ChangeState(ExistSafetyAreaEnum.SlamLost);
- return;
- }
- if (reference.alpha >= 1.1f)
- {
- reference.ChangeState(ExistSafetyAreaEnum.OutOfArea);
- return;
- }
- }
- public override void OnStateEnter(object data)
- {
- timer = 0f;
- savemapTimer = 0f;
- isOpenSeeThrough = false;
- SafetyAreaManager.Instance.OnDisableSafetyArea += OnDisableChange;
- SafetyAreaManager.Instance.OnDoubleTapShowSafetyArea += OnDoubleTapShowSafetyArea;
- API_GSXR_Slam.GSXR_Add_SlamPauseCallback(OnSlamPause);
- if (!SafetyAreaManager.Instance.isSettingSafetyArea)
- {
- SafetyAreaManager.Instance.EnterSafetyAreaInvoke();
- }
- #if !UNITY_EDITOR
- TpActionManager.Instance.ActiveTpListener(OnTpDown);
- #endif
- }
- public override void OnStateExit(object data)
- {
- #if !UNITY_EDITOR
- TpActionManager.Instance.CancelTpListener();
- #endif
- API_GSXR_Slam.GSXR_Remove_SlamPauseCallback(OnSlamPause);
- SafetyAreaManager.Instance.OnDoubleTapShowSafetyArea -= OnDoubleTapShowSafetyArea;
- SafetyAreaManager.Instance.OnDisableSafetyArea -= OnDisableChange;
- }
- private void OnSlamPause(bool isPause)
- {
- if (!isPause && !SafetyAreaManager.Instance.isDisableSafetyArea)
- {
- if (isOpenSeeThrough)
- {
- API_GSXR_Slam.GSXR_StartSeeThrough();
- }
- }
- }
- private void OnDisableChange(bool isDisable)
- {
- if (!isDisable && isOpenSeeThrough)
- {
- API_GSXR_Slam.GSXR_StartSeeThrough();
- }
- else
- {
- API_GSXR_Slam.GSXR_StopSeeThrough();
- }
- }
- private void OnDoubleTapShowSafetyArea(bool isActive)
- {
- if (!isActive)
- {
- isOpenSeeThrough = false;
- API_GSXR_Slam.GSXR_StopSeeThrough();
- }
- }
- private void OnTpDown()
- {
- if (!SafetyAreaManager.Instance.DoubleClickShowSeeThrough || SafetyAreaManager.Instance.isSettingSafetyArea || SafetyAreaManager.Instance.isDisableSafetyArea)
- {
- return;
- }
- if (tapTimer != 0f)
- {
- if (isOpenSeeThrough)
- {
- //Debug.LogError("LQR GSXR_StopSeeThrough");
- isOpenSeeThrough = false;
- API_GSXR_Slam.GSXR_StopSeeThrough();
- }
- else
- {
- //Debug.LogError("LQR GSXR_StartSeeThrough");
- isOpenSeeThrough = true;
- API_GSXR_Slam.GSXR_StartSeeThrough();
- }
- tapTimer = 0f;
- }
- else
- {
- tapTimer = TAP_TIMER;
- }
- }
- }
|