123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- using SC.XR.Unity;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class GroundHeightStep : AbstractSafetyAreaStep<SafetyAreaMono>
- {
-
- private float GROUND_HEIGHT_SET_DELAY = 2f;
- private bool canSetPlaneHeight = false;
- private float planeHeight;
- public GroundHeightStep(SafetyAreaMono safetyAreaMono) : base(safetyAreaMono)
- {
- LoadPlaneHeight();
- }
- public override void OnEnterStep(object data)
- {
-
-
- reference.groundHeightUI.Init();
- reference.groundHeightUI.OnConfirmClick += SwitchToPlayAreaStep;
- reference.groundHeightUI.OnResetClick += ResetPlaneHeight;
- reference.groundHeightUI.OnCancelClick += ExitSafetyAreaProcess;
- canSetPlaneHeight = false;
- SafetyAreaManager.Instance.DelayShow(2f, GroundHeightSetDelay);
-
- if (data != null)
- {
- LoadPlaneHeight();
- }
- else
- {
- ResetPlaneHeight();
- }
- reference.CreateSafetyPlane();
- if (!SafetyAreaManager.Instance.onlySettingGroundHeight && (data == null))
- {
- SafetyAreaManager.Instance.DelayShow(1f, DelayShowUI);
- }
- else
- {
- reference.groundHeightUI.gameObject.SetActive(true);
- reference.EnablePlaneMeshRenderer();
- SetPlayAreaMat();
- reference.safetyPlaneMono.StopPlaneAnimation();
- UnFreezePlaneHeight();
- }
- }
- public override void OnExitStep()
- {
- SavePlaneHeight();
- FreezePlaneHeight();
- SetPlayAreaConfirmedMat();
- reference.groundHeightUI.OnConfirmClick -= SwitchToPlayAreaStep;
- reference.groundHeightUI.OnResetClick -= ResetPlaneHeight;
- reference.groundHeightUI.OnCancelClick -= ExitSafetyAreaProcess;
- reference.groundHeightUI.Release();
- reference.groundHeightUI.gameObject.SetActive(false);
-
- }
- public override SafetyAreaStepEnum GetStepEnum()
- {
- return SafetyAreaStepEnum.GroundHeight;
- }
- private void GroundHeightSetDelay()
- {
- canSetPlaneHeight = true;
- }
- private void DelayShowUI()
- {
- if (SafetyAreaManager.Instance.GetCurrentStepEnum() == SafetyAreaStepEnum.GroundHeight)
- {
- reference.groundHeightUI.gameObject.SetActive(true);
- reference.EnablePlaneMeshRenderer();
- SetPlayAreaMat();
- reference.safetyPlaneMono.StopPlaneAnimation();
- UnFreezePlaneHeight();
- }
- }
- private void ExitSafetyAreaProcess()
- {
- reference.DestroySafetyPlane();
- SafetyAreaManager.Instance.ExitSafeAreaStep();
- }
- private void DelaySafetyAreaProcess()
- {
- SafetyAreaManager.Instance.DelayExitSafeAreaStep(0.7f, reference.DestroySafetyPlane);
- }
-
- public void SetPlayAreaMat()
- {
- if (reference.safetyPlaneMono == null) return;
- reference.safetyPlaneMono.SetPlaneMat(reference.safetyPlaneMat);
- reference.safetyPlaneMono.SetHoverPlaneMat(reference.safetyPlaneMat);
- }
-
- public void SetPlayAreaConfirmedMat()
- {
- if (reference.safetyPlaneMono == null) return;
- reference.safetyPlaneMono.SetPlaneMat(reference.safetyPlaneConfirmedMat);
- reference.safetyPlaneMono.SetHoverPlaneMat(reference.safetyPlaneHoverMat);
- }
-
- public void UnFreezePlaneHeight()
- {
- if (reference.safetyPlaneMono == null)
- {
- Debug.LogError("safetyPlaneMono is Null UnFreezePlaneHeight");
- return;
- }
- reference.safetyPlaneMono.UnFreezePlaneHeight();
- }
-
- public void FreezePlaneHeight()
- {
- if (reference.safetyPlaneMono == null)
- {
- return;
- }
- reference.safetyPlaneMono.FreezePlaneHeight();
- }
- private void SwitchToPlayAreaStep()
- {
- reference.safetyPlaneMono.StartPlaneAnimation();
- if (SafetyAreaManager.Instance.onlySettingGroundHeight)
- {
-
-
- DelaySafetyAreaProcess();
- return;
- }
- SafetyAreaManager.Instance.DelayChangeStep(SafetyAreaStepEnum.PlayArea, 0.7f);
- }
- public void SetHeadPosition(Vector3 headPosition)
- {
- if (!canSetPlaneHeight) return;
- float largestHeight = headPosition.y - PlayAreaConstant.DEFAULT_HEIGHT_FROM_HEAD;
- if (largestHeight < planeHeight)
- {
- planeHeight = largestHeight;
- }
- }
- public void SetPlaneHeight(float interactionObjectHeight)
- {
- if (!canSetPlaneHeight)
- {
- return;
- }
- if (interactionObjectHeight < planeHeight)
- {
- planeHeight = interactionObjectHeight;
- }
- }
- public float GetPlaneHeight()
- {
- return planeHeight;
- }
- public void ResetPlaneHeight()
- {
- planeHeight = 10000f;
- }
- public void LoadPlaneHeight()
- {
-
- planeHeight = 0f;
- }
- public void SavePlaneHeight()
- {
- float originHeight = API_Module_SDKSystem.GetSDKSystemHeight();
- API_SDKGlobalConfiguration.SetConfiguration("Module_SafetyArea", "Height", (originHeight - planeHeight).ToString());
- API_SDKGlobalConfiguration.SaveAllConfigToFile();
- API_Module_SDKSystem.SetSDKSystemHeight(originHeight - planeHeight);
-
-
-
- }
- public override void OnUserCancel()
- {
- ExitSafetyAreaProcess();
- }
- }
|