using EZXR.Glass.Plane; using EZXR.Glass.SixDof; #if SpatialComputing using EZXR.Glass.SpatialComputing; #endif #if SpatialMesh using EZXR.Glass.SpatialMesh; #endif #if Tracking2D using EZXR.Glass.Tracking2D; #endif #if Tracking3D using EZXR.Glass.Tracking3D; #endif using EZXR.Glass.Core; using UnityEditor; using UnityEngine; [CustomEditor(typeof(XRMan))] [CanEditMultipleObjects] public class XRManInspector : Editor { bool toggle_PlaneDetection = false; bool toggle_PlaneDetection_Last = false; bool toggle_SpatialMesh = false; bool toggle_SpatialMesh_Last = false; bool toggle_SpatialComputing = false; bool toggle_SpatialComputing_Last = false; bool toggle_ImageDetection = false; bool toggle_ImageDetection_Last = false; bool toggle_ObjectDetection = false; bool toggle_ObjectDetection_Last = false; XRMan xrMan; SerializedProperty m_dof; private void OnEnable() { xrMan = (XRMan)target; m_dof = serializedObject.FindProperty("m_dof"); toggle_PlaneDetection = FindObjectOfType() != null; toggle_PlaneDetection_Last = toggle_PlaneDetection; #if SpatialMesh toggle_SpatialMesh = FindObjectOfType() != null; toggle_SpatialMesh_Last = toggle_SpatialMesh; #endif #if SpatialComputing toggle_SpatialComputing = FindObjectOfType() != null; toggle_SpatialComputing_Last = toggle_SpatialComputing; #endif #if Tracking2D toggle_ImageDetection = FindObjectOfType() != null; toggle_ImageDetection_Last = toggle_ImageDetection; #endif #if Tracking3D toggle_ObjectDetection = FindObjectOfType() != null; toggle_ObjectDetection_Last = toggle_ObjectDetection; #endif } GUIContent content_Dof = new GUIContent("SpatialTracking", "基础组件,不可以被关闭!"); GUIContent content_InputSystem = new GUIContent("InputSystem", "基础组件,不可以被关闭!"); GUIContent content_SpatialMesh = new GUIContent("SpatialMesh", "启用后将会开启空间网格生成,有一定的性能开销!"); public override void OnInspectorGUI() { serializedObject.Update(); GUIStyle box = GUI.skin.box; EditorGUILayout.BeginVertical(box); { EditorGUILayout.BeginToggleGroup(content_Dof, true); { EditorGUILayout.PropertyField(m_dof, new GUIContent("DegreeOfFreedom")); toggle_SpatialMesh = EditorGUILayout.Toggle(content_SpatialMesh, toggle_SpatialMesh); } EditorGUILayout.EndToggleGroup(); } EditorGUILayout.EndVertical(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.BeginVertical(box); { EditorGUILayout.BeginToggleGroup(content_InputSystem, true); { } EditorGUILayout.EndToggleGroup(); } EditorGUILayout.EndVertical(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); #region PlaneDetection EditorGUILayout.BeginVertical(box); { toggle_PlaneDetection = EditorGUILayout.BeginToggleGroup("PlaneDetection", toggle_PlaneDetection); if (toggle_PlaneDetection_Last != toggle_PlaneDetection) { if (toggle_PlaneDetection) { if (FindObjectOfType() == null) { string filePath = "Assets/EZXRGlassSDK/Core/SixDof/Prefabs/PlaneDetectionManager.prefab"; if (AssetDatabase.LoadAssetAtPath(filePath) == null) { filePath = AssetDatabase.GUIDToAssetPath("1a44cb9e3dd5f5046a7333d3057af165"); } EZXR.Glass.Core.PrefabUtility.InstantiatePrefabWithUndo(AssetDatabase.LoadAssetAtPath(filePath), xrMan.attachments); } } else { PlaneDetectionManager planeDetectionManager = FindObjectOfType(); if (planeDetectionManager != null) { DestroyImmediate(planeDetectionManager.gameObject); } } } toggle_PlaneDetection_Last = toggle_PlaneDetection; EditorGUILayout.EndToggleGroup(); } EditorGUILayout.EndVertical(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); #endregion #region ImageDetection #if Tracking2D EditorGUILayout.BeginVertical(box); { toggle_ImageDetection = EditorGUILayout.BeginToggleGroup("ImageDetection", toggle_ImageDetection); if (toggle_ImageDetection_Last != toggle_ImageDetection) { if (toggle_ImageDetection) { if (FindObjectOfType() == null) { string filePath = "Assets/EZXRGlassSDK/Core/Tracking2D/Prefabs/Tracking2DManager.prefab"; if (AssetDatabase.LoadAssetAtPath(filePath) == null) { filePath = AssetDatabase.GUIDToAssetPath("c1ccc76a41cf54cdfb14a3580ad173f2"); } EZXR.Glass.Core.PrefabUtility.InstantiatePrefabWithUndo(AssetDatabase.LoadAssetAtPath(filePath), xrMan.attachments); } } else { Tracking2DManager imageDetectionManager = FindObjectOfType(); if (imageDetectionManager != null) { DestroyImmediate(imageDetectionManager.gameObject); } } } toggle_ImageDetection_Last = toggle_ImageDetection; EditorGUILayout.EndToggleGroup(); } EditorGUILayout.EndVertical(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); #endif #endregion #region ObjectDetection //EditorGUILayout.BeginVertical(box); //{ // toggle_ObjectDetection = EditorGUILayout.BeginToggleGroup("ObjectDetection", toggle_ObjectDetection); // if (toggle_ObjectDetection_Last != toggle_ObjectDetection) // { // if (toggle_ObjectDetection) // { // //if (FindObjectOfType() == null) // //{ // // string filePath = "Assets/EZXRGlassSDK/Core/Tracking2D/Prefabs/Tracking2DManager.prefab"; // // if (AssetDatabase.LoadAssetAtPath(filePath) == null) // // { // // filePath = AssetDatabase.GUIDToAssetPath("c1ccc76a41cf54cdfb14a3580ad173f2"); // // } // // EZXR.Glass.Core.PrefabUtility.InstantiatePrefabWithUndo(AssetDatabase.LoadAssetAtPath(filePath), xrMan.attachments); // //} // } // else // { // } // } // toggle_ObjectDetection_Last = toggle_ObjectDetection; // EditorGUILayout.EndToggleGroup(); //} //EditorGUILayout.EndVertical(); //EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); #endregion #region SpatialComputing #if SpatialComputing EditorGUILayout.BeginVertical(box); { toggle_SpatialComputing = EditorGUILayout.BeginToggleGroup("SpatialComputing", toggle_SpatialComputing); if (toggle_SpatialComputing_Last != toggle_SpatialComputing) { if (toggle_SpatialComputing) { if (FindObjectOfType() == null) { string filePath = "Assets/EZXRGlassSDK/Core/SpatialComputing/Prefabs/SpatialComputingManager.prefab"; if (AssetDatabase.LoadAssetAtPath(filePath) == null) { filePath = AssetDatabase.GUIDToAssetPath("2ff96ba100da74917a4b639f15c46cae"); } EZXR.Glass.Core.PrefabUtility.InstantiatePrefabWithUndo(AssetDatabase.LoadAssetAtPath(filePath), xrMan.attachments); } } else { EZXRSpatialComputingManager spatialComputingManager = FindObjectOfType(); if (spatialComputingManager != null) { DestroyImmediate(spatialComputingManager.gameObject); } } } toggle_SpatialComputing_Last = toggle_SpatialComputing; EditorGUILayout.EndToggleGroup(); } EditorGUILayout.EndVertical(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); #endif #endregion serializedObject.ApplyModifiedProperties(); } //private SpatialUIElement _target_SpatialUIElement; //SerializedProperty interactable; //SerializedProperty positionType; //SerializedProperty size; //SerializedProperty text; //SerializedProperty textColor; //SerializedProperty color; //SerializedProperty texture; //SerializedProperty sortingOrder; //protected virtual void OnEnable() //{ // _target_SpatialUIElement = target as SpatialUIElement; // interactable = serializedObject.FindProperty("interactable"); // positionType = serializedObject.FindProperty("positionType"); // size = serializedObject.FindProperty("size"); // text = serializedObject.FindProperty("text"); // textColor = serializedObject.FindProperty("textColor"); // color = serializedObject.FindProperty("color"); // texture = serializedObject.FindProperty("texture"); // sortingOrder = serializedObject.FindProperty("sortingOrder"); //} //public override void OnInspectorGUI() //{ // serializedObject.Update(); // EditorGUILayout.PropertyField(interactable, new GUIContent("Interactable", "是否可以与射线或者手进行交互")); // EditorGUILayout.PropertyField(positionType); // EditorGUILayout.PropertyField(size, new GUIContent("Size(单位:m)")); // EditorGUILayout.PropertyField(text); // EditorGUILayout.PropertyField(textColor); // EditorGUILayout.PropertyField(color); // EditorGUILayout.BeginHorizontal(); // { // EditorGUILayout.PropertyField(texture); // if (GUILayout.Button(new GUIContent("Set Physical Size", "按照SpatialUIController.unitsPerPixel中设定的“像素-UnityUnit转换比例”将Texture以换算后的物理尺寸绘制在空间中"))) // { // Undo.RecordObject(_target_SpatialUIElement, "Set Physical Size"); // _target_SpatialUIElement.size = new Vector3(_target_SpatialUIElement.Texture.width * _target_SpatialUIElement.curUnitsPerPixel, _target_SpatialUIElement.Texture.height * _target_SpatialUIElement.curUnitsPerPixel, _target_SpatialUIElement.size.z); // //_target_SpatialUIElement.curUnitsPerPixel = SpatialUIController.Instance.unitsPerPixel; // EditorApplication.QueuePlayerLoopUpdate(); // //SceneView.RepaintAll(); // } // } // EditorGUILayout.EndHorizontal(); // EditorGUI.BeginChangeCheck(); // _target_SpatialUIElement.sortingOrder = EditorGUILayout.DelayedIntField("SortingOrder", _target_SpatialUIElement.sortingOrder); // if (EditorGUI.EndChangeCheck()) // { // if (_target_SpatialUIElement._text != null && _target_SpatialUIElement._text.GetComponent() != null) // { // _target_SpatialUIElement._text.GetComponent().sortingOrder = _target_SpatialUIElement.sortingOrder + 1; // } // } // serializedObject.ApplyModifiedProperties(); // SceneView.RepaintAll(); //} }