123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- using Immersal.AR;
- using SC.XR.Unity.Module_InputSystem;
- using UnityEngine;
- using UnityEngine.UI;
- public class MoveChange : MonoBehaviour
- {
- public Text dingweidebug;
- 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()
- {
- #if UNITY_EDITOR
- ControllerTracker = OpenXRCamera.Instance.head;
- #else
- if(DeviceType.type!="A01"&&DeviceType.type!="Phone")
- {
- ControllerTracker = API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDeviceKSPartUI.transform;
- }else
- {
- ControllerTracker = OpenXRCamera.Instance.head;
- }
- #endif
- 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;
- }else
- {
- TempVector3Rot = OpenXRCamera.Instance.head.eulerAngles - goRefrence.transform.eulerAngles;
- }
- 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;
- }
- public void zhijiekaishi()
- {
- ARSpace.isFind = true;
- islixian = true;
- GameManager.Instance.armap.renderMode = Immersal.AR.ARMap.RenderMode.EditorAndRuntime;
- GameManager.Instance.m_SettingPanel.setdingwei(false);
- //GameManager.Instance.armap.FreeMap(true);
- }
- public static bool isCx;
- public static bool islixian;
- public GameObject saomiao;
- void Update()
- {
- if (!UserInfo.Instance.is20)
- {
- if (ARSpace.isFind)
- {
- if (!isCx)
- {
- saomiao.SetActive(false);
- txtTip.SetActive(!islixian);
- txtTip.GetComponent<ShowTipTime>().TimeFloat = 3;
- txtTip.GetComponent<ShowTipTime>().t = 0;
- txtTip.GetComponentInChildren<Text>().text = "空间定位成功";
- // XRLocalizer.Instance.gameObject.SetActive(false);
- }
- isCx = true;
- if (dingweidebug && XRLocalizer.Instance)
- {
- string sfdw = XRLocalizer.Instance.gameObject.activeSelf ? "定位开启" + XRLocalizer.Instance.stats.localizationSuccessCount + "/" + XRLocalizer.Instance.stats.localizationAttemptCount : "定位关闭";
- dingweidebug.text = sfdw;
- }
- }
- else
- {
- txtTip.SetActive(false);
- saomiao.SetActive(true);
- // txtTip.GetComponentInChildren<Text>().text = "请扫描周围环境以进行空间定位";
- }
- if (isDown && SetSceneActive.Instance.active&&!islixian)
- {
- 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
- {
- if(DeviceType.type != "A01" && DeviceType.type != "Phone")
- {
- Debug.Log("正在旋轉======》");
- v3.y = ControllerTracker_Y - ControllerTracker.eulerAngles.y;
- goRefrence.transform.localEulerAngles += v3;
- ControllerTracker_Y = ControllerTracker.eulerAngles.y;
- }else
- {
- goRefrence.transform.localEulerAngles = TempVector3Rot - ControllerTracker.eulerAngles;
- goRefrence.transform.localEulerAngles = new Vector3(0, goRefrence.transform.eulerAngles.y, 0);
- }
- /*
- 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.eulerAngles.y;
- }
- else
- {
- //txtTip.SetActive(f);
- }
- }
- private Vector3 v3 = Vector3.zero; // 用于存放手柄上次与下次的差值
- private float ControllerTracker_Y = 0; // 上次手柄的旋转Y值
- private bool IsRot;
- private Vector3 TempVector3;
- private Vector3 TempVector3Rot;
- 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;
- }
- }
- }
|