继续重构调整(UI)
- 引入 UniTask 和异步版本的 UIModule - 调整 Runtime/UIBase 和 Presentation 下的脚本命名空间到 SepCore.UI - 将原来的 5 层 UI 迁移到异步实现 - 规范各层的 UI 脚本命名
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SepCore.CustomComponent;
|
||||
using SepCore.UI;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UIModule.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<IUIFormController>())
|
||||
{
|
||||
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
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa46094acc1cee640828c3adc1f267b9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user