123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- using SC.XR.Unity;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class GroundHeightStep : AbstractSafetyAreaStep<SafetyAreaMono>
- {
- //private string PLANE_HEIGHT_SAVE_KEY = "PLANE_HEIGHT_SAVE_KEY";
- 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.gameObject.SetActive(true);
- //reference.safetyGreyCameraUI.gameObject.SetActive(true);
- 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);
- //reference.safetyGreyCameraUI.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)
- {
- //SafetyAreaManager.Instance.ResetSafetyAreaHeight();
- //ExitSafetyAreaProcess();
- 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;// - API_Module_SDKSystem.GetSDKSystemHeight();
- if (largestHeight < planeHeight)
- {
- planeHeight = largestHeight;
- }
- }
- public void SetPlaneHeight(float interactionObjectHeight)
- {
- if (!canSetPlaneHeight)
- {
- return;
- }
- if (interactionObjectHeight < planeHeight)
- {
- planeHeight = interactionObjectHeight;
- }
- }
- public float GetPlaneHeight()
- {
- return planeHeight;//+ API_Module_SDKSystem.GetSDKSystemHeight();
- }
- public void ResetPlaneHeight()
- {
- planeHeight = 10000f;//float.MaxValue;
- }
- public void LoadPlaneHeight()
- {
- //ResetPlaneHeight();
- planeHeight = 0f;//-float.Parse(API_SDKGlobalConfiguration.GetString("Module_SafetyArea", "Height", "0"));//PlayerPrefs.GetFloat(PLANE_HEIGHT_SAVE_KEY, float.MaxValue);
- }
- 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);
- //SDKGlobalConfiguration.getInstance.SaveConfigsToNative();
- //PlayerPrefs.SetFloat(PLANE_HEIGHT_SAVE_KEY, planeHeight);
- //PlayerPrefs.Save();
- }
- public override void OnUserCancel()
- {
- ExitSafetyAreaProcess();
- }
- }
|