XRManInspector.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. using EZXR.Glass.Plane;
  2. using EZXR.Glass.SixDof;
  3. #if SpatialComputing
  4. using EZXR.Glass.SpatialComputing;
  5. #endif
  6. #if SpatialMesh
  7. using EZXR.Glass.SpatialMesh;
  8. #endif
  9. #if Tracking2D
  10. using EZXR.Glass.Tracking2D;
  11. #endif
  12. #if Tracking3D
  13. using EZXR.Glass.Tracking3D;
  14. #endif
  15. using EZXR.Glass.Core;
  16. using UnityEditor;
  17. using UnityEngine;
  18. [CustomEditor(typeof(XRMan))]
  19. [CanEditMultipleObjects]
  20. public class XRManInspector : Editor
  21. {
  22. bool toggle_PlaneDetection = false;
  23. bool toggle_PlaneDetection_Last = false;
  24. bool toggle_SpatialMesh = false;
  25. bool toggle_SpatialMesh_Last = false;
  26. bool toggle_SpatialComputing = false;
  27. bool toggle_SpatialComputing_Last = false;
  28. bool toggle_ImageDetection = false;
  29. bool toggle_ImageDetection_Last = false;
  30. bool toggle_ObjectDetection = false;
  31. bool toggle_ObjectDetection_Last = false;
  32. XRMan xrMan;
  33. SerializedProperty m_dof;
  34. private void OnEnable()
  35. {
  36. xrMan = (XRMan)target;
  37. m_dof = serializedObject.FindProperty("m_dof");
  38. toggle_PlaneDetection = FindObjectOfType<PlaneDetectionManager>() != null;
  39. toggle_PlaneDetection_Last = toggle_PlaneDetection;
  40. #if SpatialMesh
  41. toggle_SpatialMesh = FindObjectOfType<SpatialMeshManager>() != null;
  42. toggle_SpatialMesh_Last = toggle_SpatialMesh;
  43. #endif
  44. #if SpatialComputing
  45. toggle_SpatialComputing = FindObjectOfType<EZXRSpatialComputingManager>() != null;
  46. toggle_SpatialComputing_Last = toggle_SpatialComputing;
  47. #endif
  48. #if Tracking2D
  49. toggle_ImageDetection = FindObjectOfType<Tracking2DManager>() != null;
  50. toggle_ImageDetection_Last = toggle_ImageDetection;
  51. #endif
  52. #if Tracking3D
  53. toggle_ObjectDetection = FindObjectOfType<Tracking3DManager>() != null;
  54. toggle_ObjectDetection_Last = toggle_ObjectDetection;
  55. #endif
  56. }
  57. GUIContent content_Dof = new GUIContent("SpatialTracking", "基础组件,不可以被关闭!");
  58. GUIContent content_InputSystem = new GUIContent("InputSystem", "基础组件,不可以被关闭!");
  59. GUIContent content_SpatialMesh = new GUIContent("SpatialMesh", "启用后将会开启空间网格生成,有一定的性能开销!");
  60. public override void OnInspectorGUI()
  61. {
  62. serializedObject.Update();
  63. GUIStyle box = GUI.skin.box;
  64. EditorGUILayout.BeginVertical(box);
  65. {
  66. EditorGUILayout.BeginToggleGroup(content_Dof, true);
  67. {
  68. EditorGUILayout.PropertyField(m_dof, new GUIContent("DegreeOfFreedom"));
  69. toggle_SpatialMesh = EditorGUILayout.Toggle(content_SpatialMesh, toggle_SpatialMesh);
  70. }
  71. EditorGUILayout.EndToggleGroup();
  72. }
  73. EditorGUILayout.EndVertical();
  74. EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
  75. EditorGUILayout.BeginVertical(box);
  76. {
  77. EditorGUILayout.BeginToggleGroup(content_InputSystem, true);
  78. {
  79. }
  80. EditorGUILayout.EndToggleGroup();
  81. }
  82. EditorGUILayout.EndVertical();
  83. EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
  84. #region PlaneDetection
  85. EditorGUILayout.BeginVertical(box);
  86. {
  87. toggle_PlaneDetection = EditorGUILayout.BeginToggleGroup("PlaneDetection", toggle_PlaneDetection);
  88. if (toggle_PlaneDetection_Last != toggle_PlaneDetection)
  89. {
  90. if (toggle_PlaneDetection)
  91. {
  92. if (FindObjectOfType<PlaneDetectionManager>() == null)
  93. {
  94. string filePath = "Assets/EZXRGlassSDK/Core/SixDof/Prefabs/PlaneDetectionManager.prefab";
  95. if (AssetDatabase.LoadAssetAtPath<GameObject>(filePath) == null)
  96. {
  97. filePath = AssetDatabase.GUIDToAssetPath("1a44cb9e3dd5f5046a7333d3057af165");
  98. }
  99. EZXR.Glass.Core.PrefabUtility.InstantiatePrefabWithUndo(AssetDatabase.LoadAssetAtPath<GameObject>(filePath), xrMan.attachments);
  100. }
  101. }
  102. else
  103. {
  104. PlaneDetectionManager planeDetectionManager = FindObjectOfType<PlaneDetectionManager>();
  105. if (planeDetectionManager != null)
  106. {
  107. DestroyImmediate(planeDetectionManager.gameObject);
  108. }
  109. }
  110. }
  111. toggle_PlaneDetection_Last = toggle_PlaneDetection;
  112. EditorGUILayout.EndToggleGroup();
  113. }
  114. EditorGUILayout.EndVertical();
  115. EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
  116. #endregion
  117. #region ImageDetection
  118. #if Tracking2D
  119. EditorGUILayout.BeginVertical(box);
  120. {
  121. toggle_ImageDetection = EditorGUILayout.BeginToggleGroup("ImageDetection", toggle_ImageDetection);
  122. if (toggle_ImageDetection_Last != toggle_ImageDetection)
  123. {
  124. if (toggle_ImageDetection)
  125. {
  126. if (FindObjectOfType<Tracking2DManager>() == null)
  127. {
  128. string filePath = "Assets/EZXRGlassSDK/Core/Tracking2D/Prefabs/Tracking2DManager.prefab";
  129. if (AssetDatabase.LoadAssetAtPath<GameObject>(filePath) == null)
  130. {
  131. filePath = AssetDatabase.GUIDToAssetPath("c1ccc76a41cf54cdfb14a3580ad173f2");
  132. }
  133. EZXR.Glass.Core.PrefabUtility.InstantiatePrefabWithUndo(AssetDatabase.LoadAssetAtPath<GameObject>(filePath), xrMan.attachments);
  134. }
  135. }
  136. else
  137. {
  138. Tracking2DManager imageDetectionManager = FindObjectOfType<Tracking2DManager>();
  139. if (imageDetectionManager != null)
  140. {
  141. DestroyImmediate(imageDetectionManager.gameObject);
  142. }
  143. }
  144. }
  145. toggle_ImageDetection_Last = toggle_ImageDetection;
  146. EditorGUILayout.EndToggleGroup();
  147. }
  148. EditorGUILayout.EndVertical();
  149. EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
  150. #endif
  151. #endregion
  152. #region ObjectDetection
  153. //EditorGUILayout.BeginVertical(box);
  154. //{
  155. // toggle_ObjectDetection = EditorGUILayout.BeginToggleGroup("ObjectDetection", toggle_ObjectDetection);
  156. // if (toggle_ObjectDetection_Last != toggle_ObjectDetection)
  157. // {
  158. // if (toggle_ObjectDetection)
  159. // {
  160. // //if (FindObjectOfType<Tracking2DManager>() == null)
  161. // //{
  162. // // string filePath = "Assets/EZXRGlassSDK/Core/Tracking2D/Prefabs/Tracking2DManager.prefab";
  163. // // if (AssetDatabase.LoadAssetAtPath<GameObject>(filePath) == null)
  164. // // {
  165. // // filePath = AssetDatabase.GUIDToAssetPath("c1ccc76a41cf54cdfb14a3580ad173f2");
  166. // // }
  167. // // EZXR.Glass.Core.PrefabUtility.InstantiatePrefabWithUndo(AssetDatabase.LoadAssetAtPath<GameObject>(filePath), xrMan.attachments);
  168. // //}
  169. // }
  170. // else
  171. // {
  172. // }
  173. // }
  174. // toggle_ObjectDetection_Last = toggle_ObjectDetection;
  175. // EditorGUILayout.EndToggleGroup();
  176. //}
  177. //EditorGUILayout.EndVertical();
  178. //EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
  179. #endregion
  180. #region SpatialComputing
  181. #if SpatialComputing
  182. EditorGUILayout.BeginVertical(box);
  183. {
  184. toggle_SpatialComputing = EditorGUILayout.BeginToggleGroup("SpatialComputing", toggle_SpatialComputing);
  185. if (toggle_SpatialComputing_Last != toggle_SpatialComputing)
  186. {
  187. if (toggle_SpatialComputing)
  188. {
  189. if (FindObjectOfType<EZXRSpatialComputingManager>() == null)
  190. {
  191. string filePath = "Assets/EZXRGlassSDK/Core/SpatialComputing/Prefabs/SpatialComputingManager.prefab";
  192. if (AssetDatabase.LoadAssetAtPath<GameObject>(filePath) == null)
  193. {
  194. filePath = AssetDatabase.GUIDToAssetPath("2ff96ba100da74917a4b639f15c46cae");
  195. }
  196. EZXR.Glass.Core.PrefabUtility.InstantiatePrefabWithUndo(AssetDatabase.LoadAssetAtPath<GameObject>(filePath), xrMan.attachments);
  197. }
  198. }
  199. else
  200. {
  201. EZXRSpatialComputingManager spatialComputingManager = FindObjectOfType<EZXRSpatialComputingManager>();
  202. if (spatialComputingManager != null)
  203. {
  204. DestroyImmediate(spatialComputingManager.gameObject);
  205. }
  206. }
  207. }
  208. toggle_SpatialComputing_Last = toggle_SpatialComputing;
  209. EditorGUILayout.EndToggleGroup();
  210. }
  211. EditorGUILayout.EndVertical();
  212. EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
  213. #endif
  214. #endregion
  215. serializedObject.ApplyModifiedProperties();
  216. }
  217. //private SpatialUIElement _target_SpatialUIElement;
  218. //SerializedProperty interactable;
  219. //SerializedProperty positionType;
  220. //SerializedProperty size;
  221. //SerializedProperty text;
  222. //SerializedProperty textColor;
  223. //SerializedProperty color;
  224. //SerializedProperty texture;
  225. //SerializedProperty sortingOrder;
  226. //protected virtual void OnEnable()
  227. //{
  228. // _target_SpatialUIElement = target as SpatialUIElement;
  229. // interactable = serializedObject.FindProperty("interactable");
  230. // positionType = serializedObject.FindProperty("positionType");
  231. // size = serializedObject.FindProperty("size");
  232. // text = serializedObject.FindProperty("text");
  233. // textColor = serializedObject.FindProperty("textColor");
  234. // color = serializedObject.FindProperty("color");
  235. // texture = serializedObject.FindProperty("texture");
  236. // sortingOrder = serializedObject.FindProperty("sortingOrder");
  237. //}
  238. //public override void OnInspectorGUI()
  239. //{
  240. // serializedObject.Update();
  241. // EditorGUILayout.PropertyField(interactable, new GUIContent("Interactable", "是否可以与射线或者手进行交互"));
  242. // EditorGUILayout.PropertyField(positionType);
  243. // EditorGUILayout.PropertyField(size, new GUIContent("Size(单位:m)"));
  244. // EditorGUILayout.PropertyField(text);
  245. // EditorGUILayout.PropertyField(textColor);
  246. // EditorGUILayout.PropertyField(color);
  247. // EditorGUILayout.BeginHorizontal();
  248. // {
  249. // EditorGUILayout.PropertyField(texture);
  250. // if (GUILayout.Button(new GUIContent("Set Physical Size", "按照SpatialUIController.unitsPerPixel中设定的“像素-UnityUnit转换比例”将Texture以换算后的物理尺寸绘制在空间中")))
  251. // {
  252. // Undo.RecordObject(_target_SpatialUIElement, "Set Physical Size");
  253. // _target_SpatialUIElement.size = new Vector3(_target_SpatialUIElement.Texture.width * _target_SpatialUIElement.curUnitsPerPixel, _target_SpatialUIElement.Texture.height * _target_SpatialUIElement.curUnitsPerPixel, _target_SpatialUIElement.size.z);
  254. // //_target_SpatialUIElement.curUnitsPerPixel = SpatialUIController.Instance.unitsPerPixel;
  255. // EditorApplication.QueuePlayerLoopUpdate();
  256. // //SceneView.RepaintAll();
  257. // }
  258. // }
  259. // EditorGUILayout.EndHorizontal();
  260. // EditorGUI.BeginChangeCheck();
  261. // _target_SpatialUIElement.sortingOrder = EditorGUILayout.DelayedIntField("SortingOrder", _target_SpatialUIElement.sortingOrder);
  262. // if (EditorGUI.EndChangeCheck())
  263. // {
  264. // if (_target_SpatialUIElement._text != null && _target_SpatialUIElement._text.GetComponent<MeshRenderer>() != null)
  265. // {
  266. // _target_SpatialUIElement._text.GetComponent<MeshRenderer>().sortingOrder = _target_SpatialUIElement.sortingOrder + 1;
  267. // }
  268. // }
  269. // serializedObject.ApplyModifiedProperties();
  270. // SceneView.RepaintAll();
  271. //}
  272. }