AlicizaX/Client/Packages/com.alicizax.unity.ui/Editor/Inspector/UIComponentInspector.cs
2025-04-28 19:45:45 +08:00

59 lines
1.8 KiB
C#

using System;
using AlicizaX.Editor;
using AlicizaX.UI.Runtime;
using UnityEditor;
using UnityEngine;
namespace AlicizaX.UI.Editor
{
[CustomEditor(typeof(UIComponent))]
internal sealed class UIComponentInspector : GameFrameworkInspector
{
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), false);
if (rootPrefab != uiRoot.objectReferenceValue)
{
uiRoot.objectReferenceValue = rootPrefab;
}
if (uiRoot.objectReferenceValue == null)
{
if (GUILayout.Button("设置默认"))
{
GameObject defaultPrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Packages/com.alicizax.unity.ui/Editor/Res/UIRoot.prefab");
uiRoot.objectReferenceValue = defaultPrefab;
}
}
EditorGUILayout.EndHorizontal();
}
EditorGUI.EndDisabledGroup();
serializedObject.ApplyModifiedProperties();
Repaint();
}
private void OnEnable()
{
uiRoot = serializedObject.FindProperty("uiRoot");
}
}
}