using SC.XR.Unity; using SC.XR.Unity.Module_InputSystem; using System.Collections; using System.Collections.Generic; using System.Reflection; using UnityEngine; public class BorderState : MonoBehaviour { CursorBase _cursorbase; MeshRenderer _mesh; GameObject _targetDeter; string _targetName; string _targetTempName; InputDevicePartBase _input; BorderSignState _signState; Color _blue ; Color _white; void ChangeState(BorderSignState state) { switch (state) { case BorderSignState.Normal: _mesh.material.color = _white; break; case BorderSignState.HighLight: _mesh.material.color = _blue; break; case BorderSignState.Selected: break; } } void InitBox() { _blue = new Color(0, 144, 255); _white = new Color(255, 255, 255); _mesh = gameObject.GetComponentInChildren(); _mesh.material.color = _white; _cursorbase = transform.parent.gameObject.GetComponent(); _input = _cursorbase.pointerBase.detectorBase.inputDevicePartBase; _targetTempName = ""; } public bool isSuiableObj(GameObject target) { if (target != null ) { if (!target.TryGetComponent(out BoundingBox box) && !target.TryGetComponent(out PressableButton btn)) { if (target.transform.parent != null) { if (target.transform.parent.name== "BoundingBox") { return false; } } return true; } } return false; } void ChangeMat() { if (isSuiableObj(_input.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject)) { _signState = BorderSignState.HighLight; } else { _signState = BorderSignState.Normal; } ChangeState(_signState); } public void AddBorder(GameObject obj) { if (obj.GetComponent() == false) { obj.AddComponent(); } if (obj.GetComponent() == false) { obj.AddComponent(); } } public void DeterTarget(InputKeyCode inputKeyCode, InputDevicePartBase part)//松开确认 { if (API_Module_AddBorder.IsEnableFunc()) { if (inputKeyCode == InputKeyCode.Enter) { _targetDeter = part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject; if (_targetDeter != null) { if (isSuiableObj(_targetDeter)) { AddBorder(_targetDeter); _mesh.material.color = _white; } } else { API_Module_AddBorder.CloseFunc(); Debug.Log("LGS:No object is currently detected"); } } } } #region private void OnEnable() { API_GSXR_Module_InputSystem.GSXR_KeyUpDelegateRegister(DeterTarget); } private void Start() { InitBox(); } private void Update() { //if (API_GSXR_Slam.SlamManager != null && !API_GSXR_Slam.GSXR_Is_SlamRunning()) //{ // return; //} if (_cursorbase != null) { if (_cursorbase.gameObject.activeSelf == false) { gameObject.SetActive(false); return; } if (_input.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject != null) { _targetName = _input.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject.name; if (_targetTempName != _targetName) { _targetTempName = _targetName; ChangeMat(); } } } } private void OnDisable() { } private void OnDestroy() { API_GSXR_Module_InputSystem.GSXR_KeyUpDelegateUnRegister(DeterTarget); _mesh = null; _cursorbase = null; _input = null; _targetDeter = null; } #endregion }