MoveChange.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using Immersal.AR;
  2. using SC.XR.Unity.Module_InputSystem;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class MoveChange : MonoBehaviour
  6. {
  7. public Text dingweidebug;
  8. public Transform ControllerTracker; // 手柄
  9. private GameObject mesh_test => SceneIOCContainer.Instance.Pull("mesh_test") as GameObject;
  10. private Transform ARSpaceForAll=>(SceneIOCContainer.Instance.Pull("ARSpaceForAll")as GameObject).transform;
  11. [SerializeField] private Toggle RotToggle;
  12. private bool isDown;
  13. private float y=> SetSceneActive.Instance.goReference_y;
  14. void Start()
  15. {
  16. #if UNITY_EDITOR
  17. ControllerTracker = OpenXRCamera.Instance.head;
  18. #else
  19. if(DeviceType.type!="A01"&&DeviceType.type!="Phone")
  20. {
  21. ControllerTracker = API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDeviceKSPartUI.transform;
  22. }else
  23. {
  24. ControllerTracker = OpenXRCamera.Instance.head;
  25. }
  26. #endif
  27. DispatcherBase.KeyDownDelegateRegister(keyDownEventDelegate);
  28. DispatcherBase.KeyUpDelegateRegister(keyUpEventDelegate);
  29. RotToggle.onValueChanged.AddListener(RotToggleOnValueChanged);
  30. IsRot = RotToggle.isOn;
  31. }
  32. private void keyUpEventDelegate(InputKeyCode keyCode, InputDevicePartBase part)
  33. {
  34. if (keyCode != InputKeyCode.Enter || goRefrence==null)
  35. {
  36. return;
  37. }
  38. Debug.Log("keyDownEventDelegate===>" + keyCode);
  39. mesh_test.transform.parent = ARSpaceForAll;
  40. goRefrence.transform.parent = ARSpaceForAll;
  41. isDown = false;
  42. }
  43. private void keyDownEventDelegate(InputKeyCode keyCode, InputDevicePartBase part)
  44. {
  45. if(keyCode != InputKeyCode.Enter)
  46. {
  47. return;
  48. }
  49. if (!SetSceneActive.Instance.active|| goRefrence==null)
  50. return;
  51. if(!IsRot)
  52. {
  53. TempVector3 = OpenXRCamera.Instance.head.position-goRefrence.transform.position;
  54. }else
  55. {
  56. TempVector3Rot = OpenXRCamera.Instance.head.eulerAngles - goRefrence.transform.eulerAngles;
  57. }
  58. mesh_test.transform.parent = goRefrence.transform;
  59. /*
  60. Debug.Log("keyUpEventDelegate===>" + keyCode);
  61. #if UNITY_EDITOR
  62. //moveGame.transform.parent = OpenXRCamera.Instance.head;
  63. #else
  64. switch (DeviceType.type)
  65. {
  66. case "Nreal":
  67. moveGame.transform.parent = API_GSXR_Module_InputSystem_KS.GSXR_KSRight.transform;// OpenXRCamera.Instance.head;
  68. break;
  69. case "A01":
  70. moveGame.transform.parent = OpenXRCamera.Instance.head;
  71. break;
  72. case "Phone":
  73. moveGame.transform.parent = OpenXRCamera.Instance.head;
  74. break;
  75. case "Rhinox":
  76. moveGame.transform.parent = API_GSXR_Module_InputSystem_KS.GSXR_KSRight.inputDeviceKSPartUI.transform;
  77. break;
  78. default:
  79. moveGame.transform.parent = API_GSXR_Module_InputSystem_KS.GSXR_KSRight.transform;// OpenXRCamera.Instance.head;
  80. break;
  81. }
  82. #endif
  83. */
  84. isDown = true;
  85. }
  86. public void zhijiekaishi()
  87. {
  88. ARSpace.isFind = true;
  89. islixian = true;
  90. GameManager.Instance.armap.renderMode = Immersal.AR.ARMap.RenderMode.EditorAndRuntime;
  91. GameManager.Instance.m_SettingPanel.setdingwei(false);
  92. //GameManager.Instance.armap.FreeMap(true);
  93. }
  94. public static bool isCx;
  95. public static bool islixian;
  96. public GameObject saomiao;
  97. void Update()
  98. {
  99. if (!UserInfo.Instance.is20)
  100. {
  101. if (ARSpace.isFind)
  102. {
  103. if (!isCx)
  104. {
  105. saomiao.SetActive(false);
  106. txtTip.SetActive(!islixian);
  107. txtTip.GetComponent<ShowTipTime>().TimeFloat = 3;
  108. txtTip.GetComponent<ShowTipTime>().t = 0;
  109. txtTip.GetComponentInChildren<Text>().text = "空间定位成功";
  110. // XRLocalizer.Instance.gameObject.SetActive(false);
  111. }
  112. isCx = true;
  113. if (dingweidebug && XRLocalizer.Instance)
  114. {
  115. string sfdw = XRLocalizer.Instance.gameObject.activeSelf ? "定位开启" + XRLocalizer.Instance.stats.localizationSuccessCount + "/" + XRLocalizer.Instance.stats.localizationAttemptCount : "定位关闭";
  116. dingweidebug.text = sfdw;
  117. }
  118. }
  119. else
  120. {
  121. txtTip.SetActive(false);
  122. saomiao.SetActive(true);
  123. // txtTip.GetComponentInChildren<Text>().text = "请扫描周围环境以进行空间定位";
  124. }
  125. if (isDown && SetSceneActive.Instance.active&&!islixian)
  126. {
  127. if(!IsRot)
  128. {
  129. goRefrence.transform.position = OpenXRCamera.Instance.head.position - TempVector3;
  130. goRefrence.transform.position = new Vector3(goRefrence.transform.position.x, y, goRefrence.transform.position.z);
  131. }
  132. else
  133. {
  134. if(DeviceType.type != "A01" && DeviceType.type != "Phone")
  135. {
  136. Debug.Log("正在旋轉======》");
  137. v3.y = ControllerTracker_Y - ControllerTracker.eulerAngles.y;
  138. goRefrence.transform.localEulerAngles += v3;
  139. ControllerTracker_Y = ControllerTracker.eulerAngles.y;
  140. }else
  141. {
  142. goRefrence.transform.localEulerAngles = TempVector3Rot - ControllerTracker.eulerAngles;
  143. goRefrence.transform.localEulerAngles = new Vector3(0, goRefrence.transform.eulerAngles.y, 0);
  144. }
  145. /*
  146. goRefrence.transform.localEulerAngles = ControllerTracker.localEulerAngles - TempVector3;
  147. goRefrence.transform.localEulerAngles = new Vector3(0, goRefrence.transform.localEulerAngles.y, 0);
  148. */
  149. }
  150. //moveGame.transform.eulerAngles = new Vector3(0, moveGame.transform.eulerAngles.y, 0);
  151. }
  152. if (Input.GetKeyDown(KeyCode.I))
  153. {
  154. ARSpace.isFind = true;
  155. }
  156. ControllerTracker_Y = ControllerTracker.eulerAngles.y;
  157. }
  158. else
  159. {
  160. //txtTip.SetActive(f);
  161. }
  162. }
  163. private Vector3 v3 = Vector3.zero; // 用于存放手柄上次与下次的差值
  164. private float ControllerTracker_Y = 0; // 上次手柄的旋转Y值
  165. private bool IsRot;
  166. private Vector3 TempVector3;
  167. private Vector3 TempVector3Rot;
  168. public GameObject goRefrence // 参照物
  169. {
  170. get =>SceneIOCContainer.Instance.Pull("goRefrence")as GameObject;
  171. }
  172. public GameObject txtTip;
  173. private void RotToggleOnValueChanged(bool isOn)
  174. {
  175. Debug.Log("选择了RotToggleOnValueChanged");
  176. txtTip.SetActive(true);
  177. if (isOn)
  178. {
  179. txtTip.GetComponentInChildren<Text>().text = "如需调整场景旋转角度,请按住手柄拖动场景\n场景将以锚点为圆心进行旋转";
  180. IsRot = true;
  181. }
  182. else
  183. {
  184. txtTip.GetComponentInChildren<Text>().text = "如需移动场景,请按住手柄拖动场景并走动\n场景将跟随您的脚步进行整体移动";
  185. IsRot = false;
  186. }
  187. }
  188. }