AlicizaX/Client/Packages/com.alicizax.unity.ui/Editor/Inspector/UIComponentInspector.cs

63 lines
2.0 KiB
C#
Raw Normal View History

2025-04-28 19:45:45 +08:00
using System;
using AlicizaX.Editor;
2025-01-24 16:21:00 +08:00
using AlicizaX.UI.Runtime;
using UnityEditor;
using UnityEngine;
namespace AlicizaX.UI.Editor
{
[CustomEditor(typeof(UIComponent))]
2025-04-28 19:45:45 +08:00
internal sealed class UIComponentInspector : GameFrameworkInspector
2025-01-24 16:21:00 +08:00
{
private SerializedProperty uiRoot;
2025-07-11 21:00:00 +08:00
private SerializedProperty _isOrthographic;
2025-01-24 16:21:00 +08:00
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();
2025-04-28 19:45:45 +08:00
GameObject rootPrefab = (GameObject)EditorGUILayout.ObjectField("UI根预设", uiRoot.objectReferenceValue, typeof(GameObject), false);
2025-01-24 16:21:00 +08:00
if (rootPrefab != uiRoot.objectReferenceValue)
{
uiRoot.objectReferenceValue = rootPrefab;
}
if (uiRoot.objectReferenceValue == null)
{
if (GUILayout.Button("设置默认"))
{
2025-03-04 18:40:14 +08:00
GameObject defaultPrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Packages/com.alicizax.unity.ui/Editor/Res/UIRoot.prefab");
2025-01-24 16:21:00 +08:00
uiRoot.objectReferenceValue = defaultPrefab;
}
}
EditorGUILayout.EndHorizontal();
2025-07-11 21:00:00 +08:00
EditorGUILayout.PropertyField(_isOrthographic);
2025-01-24 16:21:00 +08:00
}
EditorGUI.EndDisabledGroup();
serializedObject.ApplyModifiedProperties();
Repaint();
}
2025-04-28 19:45:45 +08:00
private void OnEnable()
2025-01-24 16:21:00 +08:00
{
uiRoot = serializedObject.FindProperty("uiRoot");
2025-07-11 21:00:00 +08:00
_isOrthographic = serializedObject.FindProperty("_isOrthographic");
2025-01-24 16:21:00 +08:00
}
}
}