Files
vampire-like/Assets/GameMain/Scripts/Editor/UIRouterComponentEditor.cs
T
SepComet d2ce741a37 按 UI 五层规范重构 SelectRoleForm 并整理事件目录
- SelectRoleForm 五层归位:UseCase 改为构造注入 IProcedureMenu(新增 Runtime/ProcedureInterface),RawData 暴露原始 StatModifier[] 而非展示串,Controller 复用 ItemDescUtility 拼装属性文本,并修复 OpenUIAsync(object) 合法 RawData 分支缺少 return 的误报路径
- StatModifier 去展示职责:删除 _statTypeNames / ToString,富文本格式化下沉到 Presentation 层的 ItemDescUtility.Describe(StatModifier),CreatePropDescription 改用统一入口
  - 事件目录按 UIForm 归档:Base/Event/UI/Menu/* 拆解到 SelectRoleForm/ MenuForm/ DialogForm/ DisplayItemInfoForm/ Combat/ 等各自子目录,MenuSelectRoleReturnEventArgs 改名 SelectRoleReturnEventArgs,语义归属本 UI 模块
- IUIFormController → IUIController 改名,联动 UIControllerBase / UIRouterComponent / Editor
- 同步更新 docs/UI-5层架构设计规范.md 中相关示例与 MenuForm.prefab、ProcedureMenu 引用
2026-06-16 17:09:20 +08:00

134 lines
5.0 KiB
C#

#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using SepCore.UI;
using SepCore.UIRouter;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
namespace SepCore.Editor
{
[CustomEditor(typeof(UIRouterComponent))]
public class UIRouterComponentEditor : UnityEditor.Editor
{
private SerializedProperty _bindingsProperty;
private GUIContent[] _controllerDisplayNames;
private string[] _controllerTypeNames;
private ReorderableList _bindingsList;
private void OnEnable()
{
_bindingsProperty = serializedObject.FindProperty("_controllerBindings");
BuildControllerTypeOptions();
BuildReorderableList();
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.HelpBox("配置 UIFormType 到 IUIFormController 的映射。运行时 Awake 自动注册。",
MessageType.Info);
if (GUILayout.Button("Refresh Controller List"))
{
BuildControllerTypeOptions();
}
if (_bindingsList == null)
{
EditorGUILayout.HelpBox("Bindings list init failed.", MessageType.Error);
}
else
{
_bindingsList.DoLayoutList();
}
serializedObject.ApplyModifiedProperties();
}
private void BuildReorderableList()
{
if (_bindingsProperty == null)
{
return;
}
_bindingsList = new ReorderableList(serializedObject, _bindingsProperty, true, true, true, true);
_bindingsList.drawHeaderCallback = rect => { EditorGUI.LabelField(rect, "Controller Bindings"); };
_bindingsList.elementHeight = EditorGUIUtility.singleLineHeight * 2 + 8f;
_bindingsList.drawElementCallback = DrawElement;
_bindingsList.onAddCallback = list =>
{
_bindingsProperty.InsertArrayElementAtIndex(_bindingsProperty.arraySize);
SerializedProperty item = _bindingsProperty.GetArrayElementAtIndex(_bindingsProperty.arraySize - 1);
item.FindPropertyRelative("_controllerTypeName").stringValue = string.Empty;
item.FindPropertyRelative("_uiFormType").enumValueIndex = 0;
serializedObject.ApplyModifiedProperties();
};
}
private void BuildControllerTypeOptions()
{
List<Type> controllerTypes = new();
foreach (Type type in TypeCache.GetTypesDerivedFrom<IUIController>())
{
if (type.IsAbstract || type.IsInterface || type.ContainsGenericParameters)
{
continue;
}
controllerTypes.Add(type);
}
controllerTypes.Sort((a, b) => string.CompareOrdinal(a.FullName, b.FullName));
_controllerTypeNames = new string[controllerTypes.Count + 1];
_controllerDisplayNames = new GUIContent[controllerTypes.Count + 1];
_controllerTypeNames[0] = string.Empty;
_controllerDisplayNames[0] = new GUIContent("<None>");
for (int i = 0; i < controllerTypes.Count; i++)
{
Type type = controllerTypes[i];
_controllerTypeNames[i + 1] = type.AssemblyQualifiedName;
_controllerDisplayNames[i + 1] = new GUIContent(type.FullName);
}
}
private void DrawElement(Rect rect, int index, bool isActive, bool isFocused)
{
SerializedProperty item = _bindingsProperty.GetArrayElementAtIndex(index);
SerializedProperty formTypeProperty = item.FindPropertyRelative("_uiFormType");
SerializedProperty controllerTypeProperty = item.FindPropertyRelative("_controllerTypeName");
Rect row1 = new Rect(rect.x, rect.y + 2f, rect.width, EditorGUIUtility.singleLineHeight);
Rect row2 = new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight + 6f, rect.width,
EditorGUIUtility.singleLineHeight);
EditorGUI.PropertyField(row1, formTypeProperty, new GUIContent("UI Form Type"));
DrawControllerPopup(row2, controllerTypeProperty);
}
private void DrawControllerPopup(Rect rect, SerializedProperty controllerTypeProperty)
{
int currentIndex = 0;
string currentValue = controllerTypeProperty.stringValue;
for (int i = 0; i < _controllerTypeNames.Length; i++)
{
if (_controllerTypeNames[i] == currentValue)
{
currentIndex = i;
break;
}
}
int selected =
EditorGUI.Popup(rect, new GUIContent("Controller Type"), currentIndex, _controllerDisplayNames);
controllerTypeProperty.stringValue = _controllerTypeNames[selected];
}
}
}
#endif