123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- 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<MeshRenderer>();
- _mesh.material.color = _white;
- _cursorbase = transform.parent.gameObject.GetComponent<DefaultCursor>();
- _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<BoundingBox>() == false)
- {
- obj.AddComponent<BoundingBox>();
- }
- if (obj.GetComponent<ManipulationHandler>() == false)
- {
- obj.AddComponent<ManipulationHandler>();
- }
- }
- 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
- }
|