添加编辑器界面

This commit is contained in:
2026-06-21 20:23:58 +08:00
parent 61e67c5e15
commit 8fec3b2f9e
19 changed files with 399 additions and 2 deletions
@@ -0,0 +1,16 @@
using UnityEditor;
using XericUI.OverrideUI;
namespace XericUIEditor.OverrideUI
{
[CustomEditor(typeof(XericUIrAttributeButton))]
[CanEditMultipleObjects]
internal class XericUIrAttributeButtonEditor : XericButtonEditor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
XericUIrAttributeEditorHelper.DrawAttributeTagFields(serializedObject);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 326a7ebf62af0d5419630e20cf2861e7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,17 @@
using UnityEditor;
using UnityEditor.UI;
using XericUI.OverrideUI;
namespace XericUIEditor.OverrideUI
{
[CustomEditor(typeof(XericUIrAttributeDropdown))]
[CanEditMultipleObjects]
internal class XericUIrAttributeDropdownEditor : DropdownEditor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
XericUIrAttributeEditorHelper.DrawAttributeTagFields(serializedObject);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8f8d011250fa17848a724fbb80e756fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,33 @@
using UnityEditor;
namespace XericUIEditor.OverrideUI
{
/// <summary>
/// XericUIrAttribute* 组件的 Editor 通用辅助方法
/// </summary>
internal static class XericUIrAttributeEditorHelper
{
/// <summary>
/// 绘制 _entryTag 和 _tagIndex 字段
/// 在 OnInspectorGUI 末尾调用
/// </summary>
public static void DrawAttributeTagFields(SerializedObject serializedObject)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField("Reflection UI Attribute Tag", EditorStyles.boldLabel);
serializedObject.Update();
var entryTagProp = serializedObject.FindProperty("_entryTag");
var tagIndexProp = serializedObject.FindProperty("_tagIndex");
if (entryTagProp != null)
EditorGUILayout.PropertyField(entryTagProp);
if (tagIndexProp != null)
EditorGUILayout.PropertyField(tagIndexProp);
serializedObject.ApplyModifiedProperties();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9a59db39a3dc2734bb5f3adaafbed06c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,17 @@
using UnityEditor;
using UnityEditor.UI;
using XericUI.OverrideUI;
namespace XericUIEditor.OverrideUI
{
[CustomEditor(typeof(XericUIrAttributeInputField))]
[CanEditMultipleObjects]
internal class XericUIrAttributeInputFieldEditor : InputFieldEditor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
XericUIrAttributeEditorHelper.DrawAttributeTagFields(serializedObject);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b1ce54b154544da4c8cca4b4b8063e88
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,17 @@
using UnityEditor;
using UnityEditor.UI;
using XericUI.OverrideUI;
namespace XericUIEditor.OverrideUI
{
[CustomEditor(typeof(XericUIrAttributeSlider))]
[CanEditMultipleObjects]
internal class XericUIrAttributeSliderEditor : SliderEditor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
XericUIrAttributeEditorHelper.DrawAttributeTagFields(serializedObject);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1d0a860b1f96faa44a2536f607030df9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,30 @@
using UnityEditor;
using UnityEditor.UI;
using XericUI.OverrideUI;
namespace XericUIEditor.OverrideUI
{
[CustomEditor(typeof(XericUIrAttributeText))]
[CanEditMultipleObjects]
internal class XericUIrAttributeTextEditor : ImageEditor
{
SerializedProperty _targetTextProp;
protected override void OnEnable()
{
base.OnEnable();
_targetTextProp = serializedObject.FindProperty("_targetText");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
EditorGUILayout.Space();
if (_targetTextProp != null)
EditorGUILayout.PropertyField(_targetTextProp);
XericUIrAttributeEditorHelper.DrawAttributeTagFields(serializedObject);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0a589d7a31bab924dadbb7b510489e86
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,57 @@
using UnityEditor;
using UnityEngine;
using XericUI.OverrideUI;
namespace XericUIEditor.OverrideUI
{
[CustomEditor(typeof(XericUIrAttributeTextMeshProText))]
[CanEditMultipleObjects]
internal class XericUIrAttributeTextMeshProTextEditor : Editor
{
#if dUI_TextMeshPro
SerializedProperty _targetTextProp;
#endif
SerializedProperty _entryTagProp;
SerializedProperty _tagIndexProp;
private void OnEnable()
{
#if dUI_TextMeshPro
_targetTextProp = serializedObject.FindProperty("_targetText");
#endif
_entryTagProp = serializedObject.FindProperty("_entryTag");
_tagIndexProp = serializedObject.FindProperty("_tagIndex");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
var targetComp = target as XericUIrAttributeTextMeshProText;
EditorGUILayout.LabelField("XericUIrAttributeTextMeshProText", EditorStyles.boldLabel);
EditorGUILayout.Space();
// 提示信息
EditorGUILayout.HelpBox(
"此组件为 TMP_Text 的标记附加器,需挂在与 TMP_Text 同一个 GameObject 上。\n" +
"_entryTag 和 _tagIndex 用于反射界面生成器自动绑定。",
MessageType.Info);
#if dUI_TextMeshPro
EditorGUILayout.PropertyField(_targetTextProp);
#endif
EditorGUILayout.Space();
EditorGUILayout.LabelField("Reflection UI Attribute Tag", EditorStyles.boldLabel);
if (_entryTagProp != null)
EditorGUILayout.PropertyField(_entryTagProp);
if (_tagIndexProp != null)
EditorGUILayout.PropertyField(_tagIndexProp);
serializedObject.ApplyModifiedProperties();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8226bbbc53d035e43b6811dc1f346f60
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,16 @@
using UnityEditor;
using XericUI;
using XericUI.OverrideUI;
namespace XericUIEditor.OverrideUI
{
[CustomEditor(typeof(XericUIrAttributeToggle))]
internal class XericUIrAttributeToggleEditor : XericToggleEditor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
XericUIrAttributeEditorHelper.DrawAttributeTagFields(serializedObject);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8ae7bafc6acd1b345b62d3467fc23cbb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,3 +1,4 @@
using System;
using UnityEngine;
using UnityEngine.UI;
using XericUI.Helper;
@@ -14,11 +15,11 @@ namespace XericUI.OverrideUI
{
[SerializeField]
[Tooltip("Entry 功能标记,用于自动绑定匹配")]
private XuiavrgFieldTag _entryTag = XuiavrgFieldTag.Button;
public XuiavrgFieldTag _entryTag = XuiavrgFieldTag.Button;
[SerializeField]
[Tooltip("同一 Tag 存在多个时的索引区分")]
private int _tagIndex = 0;
public int _tagIndex = 0;
public XuiavrgFieldTag EntryTag => _entryTag;
public int TagIndex => _tagIndex;
@@ -0,0 +1,94 @@
using XericUI.Helper;
using XericUI.ReflectionUIGenerator;
#if dUI_TextMeshPro
using TMPro;
using UnityEngine;
#endif
namespace XericUI.OverrideUI
{
/// <summary>
/// 带字段标记的增强 TextMeshPro 文本组件
/// 附加在 TMP_Text 所在的 GameObject 上,提供 XuiavrgFieldTag 标记,
/// 便于反射界面生成器自动绑定。同时支持从 TMP_Text 一键替换。
/// </summary>
[UnityEngine.AddComponentMenu("Xeric UI Vessel/Attribute/TextMeshPro Text", 51)]
public class XericUIrAttributeTextMeshProText : UnityEngine.MonoBehaviour, IXuiavrgFieldTagProvider
{
#if dUI_TextMeshPro
[UnityEngine.SerializeField]
[UnityEngine.Tooltip("关联的 TMP_Text 组件引用(自动获取或手动指定)")]
private TMP_Text _targetText;
/// <summary>文本内容(通过 _targetText 读写)</summary>
public string TextContent
{
get => _targetText != null ? _targetText.text : string.Empty;
set { if (_targetText) _targetText.text = value; }
}
/// <summary>文本颜色</summary>
public UnityEngine.Color TextColor
{
get => _targetText != null ? _targetText.color : UnityEngine.Color.white;
set { if (_targetText) _targetText.color = value; }
}
private void Awake()
{
if (_targetText == null)
_targetText = GetComponent<TMP_Text>();
}
#endif
[UnityEngine.SerializeField]
[UnityEngine.Tooltip("Entry 功能标记,用于自动绑定匹配")]
private XuiavrgFieldTag _entryTag = XuiavrgFieldTag.Label;
[UnityEngine.SerializeField]
[UnityEngine.Tooltip("同一 Tag 存在多个时的索引区分")]
private int _tagIndex = 0;
public XuiavrgFieldTag EntryTag => _entryTag;
public int TagIndex => _tagIndex;
#region 组件替换
#if UNITY_EDITOR
[UnityEditor.MenuItem("CONTEXT/TextMeshProUGUI/Replace To XericUIrAttributeTextMeshProText", true)]
private static bool ValidateReplaceToAttribute(UnityEditor.MenuCommand command)
{
#if dUI_TextMeshPro
return command.context is TextMeshProUGUI && !(command.context is XericUIrAttributeTextMeshProText);
#else
return false;
#endif
}
[UnityEditor.MenuItem("CONTEXT/TextMeshProUGUI/Replace To XericUIrAttributeTextMeshProText", false, 10)]
private static void ReplaceToAttribute(UnityEditor.MenuCommand command)
{
#if dUI_TextMeshPro
var tmpComp = command.context as Component;
if (tmpComp != null)
tmpComp.gameObject.AddComponent<XericUIrAttributeTextMeshProText>();
#endif
}
[UnityEditor.MenuItem("CONTEXT/TextMeshProUGUI/Replace To TextMeshProUGUI", true)]
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
=> command.context is XericUIrAttributeTextMeshProText;
[UnityEditor.MenuItem("CONTEXT/TextMeshProUGUI/Replace To TextMeshProUGUI", false, 10)]
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
{
var comp = command.context as XericUIrAttributeTextMeshProText;
if (comp != null)
UnityEngine.Object.DestroyImmediate(comp);
}
#endif
#endregion
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cd08262713d01a24bb929ead3cc680ab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: