123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- using SC.XR.Unity.Module_InputSystem;
- using SC.XR.Unity.Module_InputSystem.InputDeviceHand;
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class StationaryAreaMono : SafetyAreaBase
- {
- private bool isFreeze = true;
- private StationaryAreaStep stationaryAreaStep;
- private GroundHeightStep groundHeightStep;
- private float radius;
- private void Awake()
- {
- DontDestroyOnLoad(this.gameObject);
- }
- public override void Update()
- {
- base.Update();
- if (!isFreeze)
- {
- Vector3 headPosition = Camera.main.transform.position;
- stationaryAreaStep.SetCircleCenter(headPosition);
- Vector2 circleCenter = stationaryAreaStep.GetCircleCenter();
- this.gameObject.transform.position = new Vector3(circleCenter.x, 0f, circleCenter.y);
- }
- List<Vector4> positionList = GetInteractionObjectPosition();
- //Debug.Log(positionList.Count);
- if (positionList.Count != 0)
- {
- meshRenderer.sharedMaterial.SetInt("positionCount", positionList.Count);
- meshRenderer.sharedMaterial.SetVectorArray("interactionPosition", positionList);
- }
- distance = GetDistance(Camera.main.transform.position);
- float paramAlpha = Mathf.Lerp(0.4f, 0.8f, SafetyAreaManager.Instance.AlphaParam);
- float displayAlpha = (radius - distance) < 0f ? 1.1f : //在圈外
- (radius - distance) > paramAlpha ? 0f : //无需触发
- Mathf.Min(1.0f, ((paramAlpha - (radius - distance)) / 0.3f)); //在灵敏度范围内0~1显示
- alpha = displayAlpha;//Mathf.Max(0, (distance - radius * 0.5f) * SafetyAreaManager.Instance.AlphaParam);
- meshRenderer.sharedMaterial.SetFloat("alpha", displayAlpha);
- //var lerp = Mathf.PingPong(Time.time, duration) / duration;
- Color colorStart = colorSections[SafetyAreaManager.Instance.OriginSafetyAreaColorIndex].startColor;
- Color colorEnd = colorSections[SafetyAreaManager.Instance.OriginSafetyAreaColorIndex].endColor;
- meshRenderer.sharedMaterial.SetColor("_Color1", colorStart);
- meshRenderer.sharedMaterial.SetColor("_Color2", colorEnd);
- var lerp = Mathf.PingPong(Time.time, duration) / duration;
- meshRenderer.sharedMaterial.SetColor("settingsColor", Color.Lerp(nearColorStart, nearColorEnd, lerp));
- meshRenderer.sharedMaterial.SetVector("_MainTex_ST", new Vector4((float)perimeter / PlayAreaConstant.SAFETY_AREA_HEIGHT * 7f, 7f, 0f, -0.05f));
- if (outOfSafetyArea == null)
- {
- GameObject outOfSafetyAreaResource = Resources.Load<GameObject>("OutofSafetyArea");
- outOfSafetyArea = GameObject.Instantiate(outOfSafetyAreaResource, this.transform);
- }
- if (SafetyAreaManager.Instance.ShowAreaWhenBowHead)
- {
- if (Vector3.Angle(Camera.main.transform.forward, Vector3.down) < PlayAreaConstant.HEAD_BOW_ANGLE)
- {
- meshRenderer.sharedMaterial.SetInt("bowHead", 1);
- }
- else
- {
- meshRenderer.sharedMaterial.SetInt("bowHead", 0);
- }
- }
- else
- {
- meshRenderer.sharedMaterial.SetInt("bowHead", 0);
- }
- //if (!SafetyAreaManager.Instance.isSettingSafetyArea && !SafetyAreaManager.Instance.isDisableSafetyArea)
- //{
- // int currentRelocState = API_GSXR_Slam.GSXR_Get_OfflineMapRelocState();
- // if (currentRelocState == 0)
- // {
- // nomapUI.SetActive(true);
- // meshRenderer.enabled = false;
- // }
- // else
- // {
- // if (distance > 5f)
- // {
- // slamLostUI.gameObject.SetActive(true);
- // meshRenderer.enabled = false;
- // }
- // else
- // {
- // slamLostUI.gameObject.SetActive(false);
- // meshRenderer.enabled = true;
- // if (alpha >= 10f)
- // {
- // outOfSafetyArea.SetActive(true);
- // }
- // else
- // {
- // outOfSafetyArea.SetActive(false);
- // }
- // }
- // }
- //}
- //else
- //{
- // outOfSafetyArea.SetActive(false);
- // nomapUI.SetActive(false);
- // slamLostUI.gameObject.SetActive(false);
- // meshRenderer.enabled = true;
- //}
- if (existSafetyAreaStateMachine != null)
- {
- existSafetyAreaStateMachine.Breathe();
- }
- }
- public void FreezeStationaryAreaPosition()
- {
- isFreeze = true;
- }
- public void UnFreezeStationaryAreaPosition()
- {
- isFreeze = false;
- }
- public void SetRadius(float radius)
- {
- this.radius = radius;
- }
- public float GetRadius()
- {
- return this.radius;
- }
- public void SetMesh(Mesh mesh, float radius)
- {
- SetRadius(radius);
- if (stationaryAreaStep == null)
- {
- stationaryAreaStep = SafetyAreaManager.Instance.GetStep<StationaryAreaStep>(SafetyAreaStepEnum.StationaryArea);
- }
- if (groundHeightStep == null)
- {
- groundHeightStep = SafetyAreaManager.Instance.GetStep<GroundHeightStep>(SafetyAreaStepEnum.GroundHeight);
- }
- meshFilter = this.gameObject.AddComponent<MeshFilter>();
- meshRenderer = this.gameObject.AddComponent<MeshRenderer>();
- //meshRenderer.material = Resources.Load<Material>("Material/SafetyEdgeMat");
- meshFilter.mesh = mesh;
- //SetOriginHeight(groundHeightStep.GetPlaneHeight());
- perimeter = 2f * Mathf.PI * radius;
- }
- public float GetDistance(Vector3 position)
- {
- if (position.y >= 2.5f) return float.PositiveInfinity;
- return Vector2.Distance(new Vector2(this.gameObject.transform.position.x, this.gameObject.transform.position.z), new Vector2(position.x, position.z));
- }
- }
|