123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- using Immersal.AR;
- using SC.XR.Unity.Module_InputSystem;
- using UnityEngine;
- using UnityEngine.UI;
- public class MoveChange : MonoBehaviour
- {
- public Transform ControllerTracker; // 手柄
- private GameObject mesh_test => SceneIOCContainer.Instance.Pull("mesh_test") as GameObject;
- private Transform ARSpaceForAll=>(SceneIOCContainer.Instance.Pull("ARSpaceForAll")as GameObject).transform;
- [SerializeField] private Toggle RotToggle;
- private bool isDown;
- private float y=> SetSceneActive.Instance.goReference_y;
- void Start()
- {
- ControllerTracker = GameObject.Find("SDKSystem").transform.Find("NRInput/Right/ControllerTracker");
- DispatcherBase.KeyDownDelegateRegister(keyDownEventDelegate);
- DispatcherBase.KeyUpDelegateRegister(keyUpEventDelegate);
- RotToggle.onValueChanged.AddListener(RotToggleOnValueChanged);
- IsRot = RotToggle.isOn;
- }
- private void keyUpEventDelegate(InputKeyCode keyCode, InputDevicePartBase part)
- {
- if (keyCode != InputKeyCode.Enter || goRefrence==null)
- {
- return;
- }
- Debug.Log("keyDownEventDelegate===>" + keyCode);
- mesh_test.transform.parent = ARSpaceForAll;
- goRefrence.transform.parent = ARSpaceForAll;
- isDown = false;
- }
- private void keyDownEventDelegate(InputKeyCode keyCode, InputDevicePartBase part)
- {
- if(keyCode != InputKeyCode.Enter)
- {
- return;
- }
- if (!SetSceneActive.Instance.active|| goRefrence==null)
- return;
- if(!IsRot)
- {
- TempVector3 = OpenXRCamera.Instance.head.position-goRefrence.transform.position;
- }
- mesh_test.transform.parent = goRefrence.transform;
- /*
- Debug.Log("keyUpEventDelegate===>" + keyCode);
- #if UNITY_EDITOR
- //moveGame.transform.parent = OpenXRCamera.Instance.head;
- #else
- switch (DeviceType.type)
- {
- case "Nreal":
- moveGame.transform.parent = API_GSXR_Module_InputSystem_KS.GSXR_KSRight.transform;// OpenXRCamera.Instance.head;
- break;
- case "A01":
- moveGame.transform.parent = OpenXRCamera.Instance.head;
- break;
- case "Phone":
- moveGame.transform.parent = OpenXRCamera.Instance.head;
- break;
- case "Rhinox":
- moveGame.transform.parent = API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDeviceKSPartUI.transform;
- break;
- default:
- moveGame.transform.parent = API_GSXR_Module_InputSystem_KS.GSXR_KSRight.transform;// OpenXRCamera.Instance.head;
- break;
- }
- #endif
- */
- isDown = true;
- }
- bool isCx;
- void Update()
- {
- if (ARSpace.isFind)
- {
- if (!isCx)
- {
- txtTip.SetActive(true);
- txtTip.GetComponent<ShowTipTime>().TimeFloat = 3;
- txtTip.GetComponent<ShowTipTime>().t = 0;
- txtTip.GetComponentInChildren<Text>().text = "空间定位成功";
- }
- isCx = true;
- }
- else
- {
- txtTip.SetActive(true);
- txtTip.GetComponentInChildren<Text>().text = "请扫描周围环境以进行空间定位";
- }
- if (isDown && SetSceneActive.Instance.active)
- {
- if(!IsRot)
- {
- goRefrence.transform.position = OpenXRCamera.Instance.head.position - TempVector3;
- goRefrence.transform.position = new Vector3(goRefrence.transform.position.x, y, goRefrence.transform.position.z);
- }
- else
- {
- v3.y = ControllerTracker_Y - ControllerTracker.localEulerAngles.y;
- goRefrence.transform.localEulerAngles +=v3;
- ControllerTracker_Y = ControllerTracker.localEulerAngles.y;
- /*
- goRefrence.transform.localEulerAngles = ControllerTracker.localEulerAngles - TempVector3;
- goRefrence.transform.localEulerAngles = new Vector3(0, goRefrence.transform.localEulerAngles.y, 0);
- */
- }
- //moveGame.transform.eulerAngles = new Vector3(0, moveGame.transform.eulerAngles.y, 0);
- }
- if (Input.GetKeyDown(KeyCode.I))
- {
- ARSpace.isFind = true;
- }
- ControllerTracker_Y = ControllerTracker.localEulerAngles.y;
- }
- private Vector3 v3 = Vector3.zero; // 用于存放手柄上次与下次的差值
- private float ControllerTracker_Y = 0; // 上次手柄的旋转Y值
- private bool IsRot;
- private Vector3 TempVector3;
- public GameObject goRefrence // 参照物
- {
- get =>SceneIOCContainer.Instance.Pull("goRefrence")as GameObject;
- }
- public GameObject txtTip;
- private void RotToggleOnValueChanged(bool isOn)
- {
- Debug.Log("选择了RotToggleOnValueChanged");
- txtTip.SetActive(true);
- if (isOn)
- {
- txtTip.GetComponentInChildren<Text>().text = "如需调整场景旋转角度,请按住手柄拖动场景\n场景将以锚点为圆心进行旋转";
- IsRot = true;
- }
- else
- {
- txtTip.GetComponentInChildren<Text>().text = "如需移动场景,请按住手柄拖动场景并走动\n场景将跟随您的脚步进行整体移动";
- IsRot = false;
- }
- }
- }
|