using AlicizaX.Editor; using AlicizaX.UI.Runtime; using UnityEditor; using UnityEngine; namespace AlicizaX.UI.Editor { [CustomEditor(typeof(UIComponent))] internal sealed class UIComponentInspector : ComponentTypeComponentInspector { private SerializedProperty uiRoot; public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode); { if (uiRoot.objectReferenceValue == null) { EditorGUILayout.HelpBox("uiroot can not be null!", MessageType.Error); } EditorGUILayout.BeginHorizontal(); GameObject rootPrefab = (GameObject)EditorGUILayout.ObjectField("UI根预设", uiRoot.objectReferenceValue, typeof(GameObject)); if (rootPrefab != uiRoot.objectReferenceValue) { uiRoot.objectReferenceValue = rootPrefab; } if (uiRoot.objectReferenceValue == null) { if (GUILayout.Button("设置默认")) { GameObject defaultPrefab = AssetDatabase.LoadAssetAtPath("Packages/com.alicizax.unity.ui/Resources/UIRoot.prefab"); uiRoot.objectReferenceValue = defaultPrefab; } } EditorGUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); serializedObject.ApplyModifiedProperties(); Repaint(); } protected override void RefreshTypeNames() { RefreshComponentTypeNames(typeof(IUIManager)); } protected override void Enable() { uiRoot = serializedObject.FindProperty("uiRoot"); } } }