123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- using SC.XR.Unity.Module_InputSystem;
- using SC.XR.Unity.Module_InputSystem.InputDeviceHand;
- using System.Collections.Generic;
- using UnityEngine;
- public class SafetyAreaBase : MonoBehaviour
- {
- //protected float originHeight;
- protected MeshFilter meshFilter;
- protected List<Vector4> positionList;
- protected float perimeter;
- protected ExistSafetyAreaStateMachine existSafetyAreaStateMachine;
- public MeshRenderer meshRenderer;
- public GameObject outOfSafetyArea;
- public GameObject nomapUI;
- public GameObject slamLostUI;
- public float distance;
- public float alpha;
- protected float duration = 1.0f;
- protected List<ColorSection> colorSections = new List<ColorSection>()
- {
- new ColorSection(){ startColor = new Color(0.129f, 0.235f, 0.886f), endColor = new Color(0.118f, 0.365f, 0.051f) },
- new ColorSection(){ startColor = new Color(0.890f, 0.102f, 0.090f), endColor = new Color(0f, 0.482f, 0.012f) },
- new ColorSection(){ startColor = new Color(0.263f, 0.145f, 0.176f), endColor = new Color(0.639f, 0.098f, 0.3012f) }
- };
- protected Color nearColorStart = new Color(0.8902f, 0.102f, 0.09f, 1f);
- protected Color nearColorEnd = new Color(0.8902f, 0.5843f, 0.102f, 1f);
- public void Init()
- {
- if (existSafetyAreaStateMachine == null)
- {
- existSafetyAreaStateMachine = new ExistSafetyAreaStateMachine();
- existSafetyAreaStateMachine.InitStateMachine(this);
- }
- ChangeState(ExistSafetyAreaEnum.Normal);
- }
- public void Release()
- {
- if (existSafetyAreaStateMachine != null)
- {
- existSafetyAreaStateMachine.ExitCurrentState();
- }
- }
- /// <summary>
- /// 设置原始高度用于计算高度delta
- /// </summary>
- /// <param name="height"></param>
- //public void SetOriginHeight(float height)
- //{
- // this.originHeight = height;
- //}
- /// <summary>
- /// 获取原始高度
- /// </summary>
- /// <returns></returns>
- //public float GetOriginHeight()
- //{
- // return this.originHeight;
- //}
- /// <summary>
- /// 设置周长
- /// </summary>
- /// <param name="perimeter"></param>
- public void SetPerimeter(float perimeter)
- {
- this.perimeter = perimeter;
- }
- /// <summary>
- /// 获取周长
- /// </summary>
- /// <returns></returns>
- public float GetPerimter()
- {
- return perimeter;
- }
- /// <summary>
- /// 重新设置高度
- /// </summary>
- /// <param name="height"></param>
- public void ResetPlaneHeight(float height)
- {
- //float heightdelta = height - originHeight;
- //this.transform.position = new Vector3(this.transform.position.x, heightdelta, this.transform.position.z);
- }
- public void SetMaterial(Material mat)
- {
- meshRenderer.sharedMaterial = mat;
- }
- public virtual void Update()
- {
- if (outOfSafetyArea == null)
- {
- GameObject outOfSafetyAreaResource = Resources.Load<GameObject>("OutofSafetyArea");
- outOfSafetyArea = GameObject.Instantiate(outOfSafetyAreaResource, this.transform);
- }
- if (nomapUI == null)
- {
- GameObject nomapUIResource = Resources.Load<GameObject>("NoMapUI");
- nomapUI = GameObject.Instantiate(nomapUIResource, this.transform);
- }
- if (slamLostUI == null)
- {
- GameObject slamLostResource = Resources.Load<GameObject>("SlamLostUI");
- slamLostUI = GameObject.Instantiate(slamLostResource, this.transform);
- }
- if (meshRenderer == null)
- {
- meshRenderer = this.GetComponent<MeshRenderer>();
- }
- if (meshFilter == null)
- {
- meshFilter = this.GetComponent<MeshFilter>();
- }
- //if (!SafetyAreaManager.Instance.isSettingSafetyArea)
- //{
- // meshRenderer.enabled = API_GSXR_Slam.GSXR_Get_OfflineMapRelocState() == 1;
- //}
- //else
- //{
- // meshRenderer.enabled = true;
- //}
- }
- public virtual void ChangeState(ExistSafetyAreaEnum existSafetyAreaEnum)
- {
- if (existSafetyAreaStateMachine != null)
- {
- existSafetyAreaStateMachine.ChangeState(existSafetyAreaEnum);
- }
- }
- protected List<Vector4> GetInteractionObjectPosition()
- {
- if (positionList == null)
- {
- positionList = new List<Vector4>();
- }
- positionList.Clear();
- if (Module_InputSystem.instance == null) return positionList;
- Vector3 headTransformPosition = Camera.main.transform.position + Camera.main.transform.forward * 0.5f;
- Vector3 viewportPosition = Camera.main.WorldToViewportPoint(headTransformPosition);
- positionList.Add(new Vector4(viewportPosition.x, viewportPosition.y, viewportPosition.z, 1f));
- if (Module_InputSystem.instance.IsSomeDeviceActiveWithoutHead)
- {
- if (Module_InputSystem.instance.GetInputDeviceStatus(InputDeviceType.GGT26Dof))
- {
- InputDeviceBase inputDevice = Module_InputSystem.instance.GetInputDevice<InputDeviceBase>(InputDeviceType.GGT26Dof);
- foreach (var part in inputDevice.inputDevicePartList)
- {
- if (part.inputDataBase.isVaild == true)
- {
- GameObject handModlePart = (part as InputDeviceHandPart).inputDeviceHandPartUI.modelHand.ActiveHandModel.GetJointTransform(FINGER.forefinger, JOINT.One).gameObject;
- Vector3 partPosition = handModlePart.transform.position;// + handModlePart.transform.forward * 0.5f;
- Vector3 viewportPartPosition = Camera.main.WorldToViewportPoint(partPosition);
- positionList.Add(new Vector4(viewportPartPosition.x, viewportPartPosition.y, viewportPartPosition.z, 1f));
- }
- }
- }
- else if (Module_InputSystem.instance.GetInputDeviceStatus(InputDeviceType.KS))
- {
- InputDeviceBase inputDevice = Module_InputSystem.instance.GetInputDevice<InputDeviceBase>(InputDeviceType.KS);
- foreach (var part in inputDevice.inputDevicePartList)
- {
- if (part.inputDataBase.isVaild == true)
- {
- GameObject KSPart = part.inputDevicePartUIBase.gameObject;
- Vector3 partPosition = KSPart.transform.position;// + KSPart.transform.forward * 0.5f;
- Vector3 viewportPartPosition = Camera.main.WorldToViewportPoint(partPosition);
- positionList.Add(new Vector4(viewportPartPosition.x, viewportPartPosition.y, viewportPartPosition.z, 1f));
- }
- }
- }
- else if (Module_InputSystem.instance.GetInputDeviceStatus(InputDeviceType.BT3Dof))
- {
- InputDeviceBase inputDevice = Module_InputSystem.instance.GetInputDevice<InputDeviceBase>(InputDeviceType.BT3Dof);
- foreach (var part in inputDevice.inputDevicePartList)
- {
- if (part.inputDataBase.isVaild == true)
- {
- GameObject BT3DofPart = part.inputDevicePartUIBase.gameObject;
- Vector3 partPosition = BT3DofPart.transform.position;// + BT3DofPart.transform.forward * 0.5f;
- Vector3 viewportPartPosition = Camera.main.WorldToViewportPoint(partPosition);
- positionList.Add(new Vector4(viewportPartPosition.x, viewportPartPosition.y, viewportPartPosition.z, 1f));
- }
- }
- }
- }
- if (positionList.Count < 3)
- {
- for (int i = positionList.Count; i < 3; i++)
- {
- positionList.Add(new Vector4(viewportPosition.x, viewportPosition.y, viewportPosition.z, 1f));
- }
- }
- return positionList;
- }
- }
|