重构反射生成属性界面
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
namespace XericUI.ReflectionUIGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// MDVM 值组件样式扩展接口
|
||||
/// 实现此接口的脚本可挂载到 XUIAvrgMDValue 预制体的子节点上,
|
||||
/// 在元数据绑定阶段由 XUIAvrgMDValue 自动调用 ApplyMetaData
|
||||
/// </summary>
|
||||
public interface IXUIAvrgMDValueStyle
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用元数据以控制组件样式
|
||||
/// </summary>
|
||||
/// <param name="metaData">当前绑定的元数据</param>
|
||||
void ApplyMetaData(AvrgMemberMetaData metaData);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd5f00c3fa1461a4e8b222779a796cc9
|
||||
guid: dfd29eb0237f4e644a57bfe7046e8d7a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XericUI.ReflectionUIGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// MDVM 值组件 — 统一 UI 脚本组件
|
||||
/// 替换所有 XericUIrAttributeXXX 作为预制体上的标记组件
|
||||
///
|
||||
/// 职责:
|
||||
/// 1. 提供 EntryTag/TagIndex 供 XuiFieldTempEntry 匹配
|
||||
/// 2. 持有绑定的 AvrgMemberMetaData 引用
|
||||
/// 3. 初始化时广播元数据到所有子节点上的 IXUIAvrgMDValueStyle
|
||||
/// </summary>
|
||||
[AddComponentMenu("Xeric Library/UI Action Vessel/XUIAvrgMDValue")]
|
||||
public class XUIAvrgMDValue : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
[Tooltip("功能标记,用于与 Entry 的 Tag 匹配")]
|
||||
private XuiavrgFieldTag _entryTag = XuiavrgFieldTag.None;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("同 Tag 多实例时区分(0 表示不限制)")]
|
||||
private int _tagIndex;
|
||||
|
||||
/// <summary>绑定的元数据引用</summary>
|
||||
public AvrgMemberMetaData BoundMetaData { get; private set; }
|
||||
|
||||
public XuiavrgFieldTag EntryTag => _entryTag;
|
||||
public int TagIndex => _tagIndex;
|
||||
|
||||
/// <summary>
|
||||
/// 由绑定系统调用,传递元数据并广播到 IXUIAvrgMDValueStyle 子组件
|
||||
/// </summary>
|
||||
public void InitializeWithMetaData(AvrgMemberMetaData metaData)
|
||||
{
|
||||
BoundMetaData = metaData;
|
||||
|
||||
if (metaData == null) return;
|
||||
|
||||
// 查找子节点上的所有样式扩展组件并广播元数据
|
||||
var styles = GetComponentsInChildren<IXUIAvrgMDValueStyle>(true);
|
||||
foreach (var style in styles)
|
||||
{
|
||||
// 跳过自身(XUIAvrgMDValue 不是 IXUIAvrgMDValueStyle)
|
||||
if (style is MonoBehaviour mb && mb.gameObject == gameObject)
|
||||
continue;
|
||||
|
||||
style.ApplyMetaData(metaData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f39882be385237b4791af43ba89fec27
|
||||
guid: 94518c2eae79c634393df9ebf950bef6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,55 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XericUI.Helper;
|
||||
using XericUI.ReflectionUIGenerator;
|
||||
|
||||
namespace XericUI.OverrideUI
|
||||
{
|
||||
/// <summary>
|
||||
/// 带字段标记的增强按钮组件
|
||||
/// 继承 XericButton,额外支持 XuiavrgFieldTag 标记,便于反射界面生成器自动绑定
|
||||
/// </summary>
|
||||
[AddComponentMenu("Xeric UI Vessel/Attribute/Button", 51)]
|
||||
public class XericUIrAttributeButton : XericButton, IXuiavrgFieldTagProvider
|
||||
{
|
||||
[SerializeField]
|
||||
[Tooltip("Entry 功能标记,用于自动绑定匹配")]
|
||||
public XuiavrgFieldTag _entryTag = XuiavrgFieldTag.Button;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("同一 Tag 存在多个时的索引区分")]
|
||||
public int _tagIndex = 0;
|
||||
|
||||
public XuiavrgFieldTag EntryTag => _entryTag;
|
||||
public int TagIndex => _tagIndex;
|
||||
|
||||
#region 组件替换
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Xeric (Attribute)", true)]
|
||||
private static bool ValidateReplaceToXeric(UnityEditor.MenuCommand command)
|
||||
=> command.context is Button and not XericUIrAttributeButton;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Xeric (Attribute)", false, 12)]
|
||||
private static void ReplaceToXeric(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<Button, XericUIrAttributeButton,
|
||||
(Graphic targetGraphic, Button.ButtonClickedEvent onClick)>(
|
||||
o => (o.targetGraphic, o.onClick),
|
||||
(t, d) => { t.targetGraphic = d.targetGraphic; t.onClick = d.onClick; });
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Unity Button (Attribute)", true)]
|
||||
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericUIrAttributeButton;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Button/Replace To/Unity Button (Attribute)", false, 100)]
|
||||
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericUIrAttributeButton, Button,
|
||||
(Graphic targetGraphic, Button.ButtonClickedEvent onClick)>(
|
||||
o => (o.targetGraphic, o.onClick),
|
||||
(t, d) => { t.targetGraphic = d.targetGraphic; t.onClick = d.onClick; });
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XericUI.Helper;
|
||||
using XericUI.ReflectionUIGenerator;
|
||||
|
||||
namespace XericUI.OverrideUI
|
||||
{
|
||||
/// <summary>
|
||||
/// 带字段标记的增强下拉框组件
|
||||
/// 继承 Unity Dropdown,额外支持 XuiavrgFieldTag 标记,便于反射界面生成器自动绑定
|
||||
/// </summary>
|
||||
[AddComponentMenu("Xeric UI Vessel/Attribute/Dropdown", 51)]
|
||||
public class XericUIrAttributeDropdown : Dropdown, IXuiavrgFieldTagProvider
|
||||
{
|
||||
[SerializeField]
|
||||
[Tooltip("Entry 功能标记,用于自动绑定匹配")]
|
||||
private XuiavrgFieldTag _entryTag = XuiavrgFieldTag.Dropdown;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("同一 Tag 存在多个时的索引区分")]
|
||||
private int _tagIndex = 0;
|
||||
|
||||
public XuiavrgFieldTag EntryTag => _entryTag;
|
||||
public int TagIndex => _tagIndex;
|
||||
|
||||
#region 组件替换
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.MenuItem("CONTEXT/Dropdown/Replace To/Xeric (Attribute)", true)]
|
||||
private static bool ValidateReplaceToAttribute(UnityEditor.MenuCommand command)
|
||||
=> command.context is Dropdown and not XericUIrAttributeDropdown;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Dropdown/Replace To/Xeric (Attribute)", false, 10)]
|
||||
private static void ReplaceToAttribute(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<Dropdown, XericUIrAttributeDropdown,
|
||||
(Graphic targetGraphic, int value, List<OptionData> options, DropdownEvent onValueChanged)>(
|
||||
o =>
|
||||
(o.targetGraphic, o.value, o.options, o.onValueChanged),
|
||||
(t, d) =>
|
||||
{
|
||||
t.targetGraphic = d.targetGraphic;
|
||||
t.value = d.value;
|
||||
t.options = d.options;
|
||||
t.onValueChanged = d.onValueChanged;
|
||||
});
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Dropdown/Replace To/Unity Dropdown", true)]
|
||||
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericUIrAttributeDropdown;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Dropdown/Replace To/Unity Dropdown", false, 100)]
|
||||
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericUIrAttributeDropdown, Dropdown,
|
||||
(Graphic targetGraphic, int value, List<OptionData> options, DropdownEvent onValueChanged)>(
|
||||
o =>
|
||||
(o.targetGraphic, o.value, o.options, o.onValueChanged),
|
||||
(t, d) =>
|
||||
{
|
||||
t.targetGraphic = d.targetGraphic;
|
||||
t.value = d.value;
|
||||
t.options = d.options;
|
||||
t.onValueChanged = d.onValueChanged;
|
||||
});
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f84f2204fb53b04fbf647213e92b0f9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,66 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XericUI.Helper;
|
||||
using XericUI.ReflectionUIGenerator;
|
||||
|
||||
namespace XericUI.OverrideUI
|
||||
{
|
||||
/// <summary>
|
||||
/// 带字段标记的增强输入框组件
|
||||
/// 继承 Unity InputField,额外支持 XuiavrgFieldTag 标记,便于反射界面生成器自动绑定
|
||||
/// </summary>
|
||||
[AddComponentMenu("Xeric UI Vessel/Attribute/InputField", 51)]
|
||||
public class XericUIrAttributeInputField : InputField, IXuiavrgFieldTagProvider
|
||||
{
|
||||
[SerializeField]
|
||||
[Tooltip("Entry 功能标记,用于自动绑定匹配")]
|
||||
private XuiavrgFieldTag _entryTag = XuiavrgFieldTag.Input;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("同一 Tag 存在多个时的索引区分")]
|
||||
private int _tagIndex = 0;
|
||||
|
||||
public XuiavrgFieldTag EntryTag => _entryTag;
|
||||
public int TagIndex => _tagIndex;
|
||||
|
||||
#region 组件替换
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.MenuItem("CONTEXT/InputField/Replace To/Xeric (Attribute)", true)]
|
||||
private static bool ValidateReplaceToAttribute(UnityEditor.MenuCommand command)
|
||||
=> command.context is InputField and not XericUIrAttributeInputField;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/InputField/Replace To/Xeric (Attribute)", false, 10)]
|
||||
private static void ReplaceToAttribute(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<InputField, XericUIrAttributeInputField,
|
||||
(Graphic targetGraphic, string text, InputField.OnChangeEvent onValueChanged, InputField.EndEditEvent onEndEdit)>(
|
||||
o => (o.targetGraphic, o.text, o.onValueChanged, o.onEndEdit),
|
||||
(t, d) =>
|
||||
{
|
||||
t.targetGraphic = d.targetGraphic;
|
||||
t.text = d.text;
|
||||
t.onValueChanged = d.onValueChanged;
|
||||
t.onEndEdit = d.onEndEdit;
|
||||
});
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/InputField/Replace To/Unity InputField", true)]
|
||||
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericUIrAttributeInputField;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/InputField/Replace To/Unity InputField", false, 100)]
|
||||
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericUIrAttributeInputField, InputField,
|
||||
(Graphic targetGraphic, string text, InputField.OnChangeEvent onValueChanged, InputField.EndEditEvent onEndEdit)>(
|
||||
o => (o.targetGraphic, o.text, o.onValueChanged, o.onEndEdit),
|
||||
(t, d) =>
|
||||
{
|
||||
t.targetGraphic = d.targetGraphic;
|
||||
t.text = d.text;
|
||||
t.onValueChanged = d.onValueChanged;
|
||||
t.onEndEdit = d.onEndEdit;
|
||||
});
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XericUI.Helper;
|
||||
using XericUI.ReflectionUIGenerator;
|
||||
|
||||
namespace XericUI.OverrideUI
|
||||
{
|
||||
/// <summary>
|
||||
/// 带字段标记的增强滑块组件
|
||||
/// 继承 Unity Slider,额外支持 XuiavrgFieldTag 标记,便于反射界面生成器自动绑定
|
||||
/// </summary>
|
||||
[AddComponentMenu("Xeric UI Vessel/Attribute/Slider", 51)]
|
||||
public class XericUIrAttributeSlider : Slider, IXuiavrgFieldTagProvider
|
||||
{
|
||||
[SerializeField]
|
||||
[Tooltip("Entry 功能标记,用于自动绑定匹配")]
|
||||
private XuiavrgFieldTag _entryTag = XuiavrgFieldTag.Slider;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("同一 Tag 存在多个时的索引区分")]
|
||||
private int _tagIndex = 0;
|
||||
|
||||
public XuiavrgFieldTag EntryTag => _entryTag;
|
||||
public int TagIndex => _tagIndex;
|
||||
|
||||
#region 组件替换
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.MenuItem("CONTEXT/Slider/Replace To/Xeric (Attribute)", true)]
|
||||
private static bool ValidateReplaceToAttribute(UnityEditor.MenuCommand command)
|
||||
=> command.context is Slider and not XericUIrAttributeSlider;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Slider/Replace To/Xeric (Attribute)", false, 10)]
|
||||
private static void ReplaceToAttribute(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<Slider, XericUIrAttributeSlider,
|
||||
(Graphic targetGraphic, float value, Slider.SliderEvent onValueChanged)>(
|
||||
o =>
|
||||
(o.targetGraphic, o.value, o.onValueChanged),
|
||||
(t, d) =>
|
||||
{
|
||||
t.targetGraphic = d.targetGraphic;
|
||||
t.value = d.value;
|
||||
t.onValueChanged = d.onValueChanged;
|
||||
});
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Slider/Replace To/Unity Slider", true)]
|
||||
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericUIrAttributeSlider;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Slider/Replace To/Unity Slider", false, 100)]
|
||||
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericUIrAttributeSlider, Slider,
|
||||
(Graphic targetGraphic, float value, Slider.SliderEvent onValueChanged)>(
|
||||
o =>
|
||||
(o.targetGraphic, o.value, o.onValueChanged),
|
||||
(t, d) =>
|
||||
{
|
||||
t.targetGraphic = d.targetGraphic;
|
||||
t.value = d.value;
|
||||
t.onValueChanged = d.onValueChanged;
|
||||
});
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XericUI.Helper;
|
||||
using XericUI.ReflectionUIGenerator;
|
||||
|
||||
namespace XericUI.OverrideUI
|
||||
{
|
||||
/// <summary>
|
||||
/// 带字段标记的增强文本组件
|
||||
/// 继承 XericImage,额外支持 XuiavrgFieldTag 标记。
|
||||
/// 主要用于预制体中标记 Label/Output/Sign 等文本功能元素
|
||||
/// </summary>
|
||||
[AddComponentMenu("Xeric UI Vessel/Attribute/Text", 51)]
|
||||
public class XericUIrAttributeText : XericImage, IXuiavrgFieldTagProvider
|
||||
{
|
||||
[SerializeField]
|
||||
[Tooltip("关联的 Text 组件引用(可选,用于读取/写入文本内容)")]
|
||||
private Text _targetText;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Entry 功能标记,用于自动绑定匹配")]
|
||||
private XuiavrgFieldTag _entryTag = XuiavrgFieldTag.Label;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("同一 Tag 存在多个时的索引区分")]
|
||||
private int _tagIndex = 0;
|
||||
|
||||
public XuiavrgFieldTag EntryTag => _entryTag;
|
||||
public int TagIndex => _tagIndex;
|
||||
|
||||
/// <summary>文本内容(通过 _targetText 读写)</summary>
|
||||
public string TextContent
|
||||
{
|
||||
get => _targetText != null ? _targetText.text : string.Empty;
|
||||
set { if (_targetText) _targetText.text = value; }
|
||||
}
|
||||
|
||||
/// <summary>文本颜色</summary>
|
||||
public Color TextColor
|
||||
{
|
||||
get => _targetText != null ? _targetText.color : Color.white;
|
||||
set { if (_targetText) _targetText.color = value; }
|
||||
}
|
||||
|
||||
#region 组件替换
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Xeric (AttributeText)", true)]
|
||||
private static bool ValidateReplaceToAttribute(UnityEditor.MenuCommand command)
|
||||
=> command.context is Image and not XericUIrAttributeText;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Xeric (AttributeText)", false, 13)]
|
||||
private static void ReplaceToAttribute(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<Image, XericUIrAttributeText, Sprite>(
|
||||
o => o.sprite,
|
||||
(t, d) => { t.sprite = d; });
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Unity Image (Attribute)", true)]
|
||||
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericUIrAttributeText;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Image/Replace To/Unity Image (Attribute)", false, 100)]
|
||||
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericUIrAttributeText, Image, Sprite>(
|
||||
o => o.sprite,
|
||||
(t, d) => { t.sprite = d; });
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5189154ac8f148f449041fd8890c9730
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,97 +0,0 @@
|
||||
using XericUI.ReflectionUIGenerator;
|
||||
|
||||
#if dUI_TextMeshPro
|
||||
using TMPro;
|
||||
#endif
|
||||
|
||||
namespace XericUI.OverrideUI
|
||||
{
|
||||
/// <summary>
|
||||
/// 带字段标记的增强 TextMeshPro 输入框组件
|
||||
/// 附加在 TMP_InputField 所在的 GameObject 上,提供 XuiavrgFieldTag 标记,
|
||||
/// 便于反射界面生成器自动绑定。支持从 TMP_InputField 一键替换。
|
||||
/// </summary>
|
||||
[UnityEngine.AddComponentMenu("Xeric UI Vessel/Attribute/TextMeshPro InputField", 51)]
|
||||
public class XericUIrAttributeTextMeshProInputField : UnityEngine.MonoBehaviour, IXuiavrgFieldTagProvider
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Tooltip("关联的 TMP_InputField 组件引用(自动获取或手动指定)")]
|
||||
private TMP_InputField _targetInputField;
|
||||
|
||||
/// <summary>输入文本内容</summary>
|
||||
public string TextContent
|
||||
{
|
||||
get => _targetInputField != null ? _targetInputField.text : string.Empty;
|
||||
set { if (_targetInputField) _targetInputField.text = value; }
|
||||
}
|
||||
|
||||
/// <summary>占位符文本</summary>
|
||||
public string Placeholder
|
||||
{
|
||||
get => _targetInputField != null && _targetInputField.placeholder is TMPro.TMP_Text ph
|
||||
? ph.text : string.Empty;
|
||||
set
|
||||
{
|
||||
if (_targetInputField && _targetInputField.placeholder is TMPro.TMP_Text ph)
|
||||
ph.text = value;
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (_targetInputField == null)
|
||||
_targetInputField = GetComponent<TMP_InputField>();
|
||||
}
|
||||
#endif
|
||||
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Tooltip("Entry 功能标记,用于自动绑定匹配")]
|
||||
private XuiavrgFieldTag _entryTag = XuiavrgFieldTag.Input;
|
||||
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Tooltip("同一 Tag 存在多个时的索引区分")]
|
||||
private int _tagIndex = 0;
|
||||
|
||||
public XuiavrgFieldTag EntryTag => _entryTag;
|
||||
public int TagIndex => _tagIndex;
|
||||
|
||||
#region 组件替换
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.MenuItem("CONTEXT/TMP_InputField/Replace To/Xeric (Attribute)", true)]
|
||||
private static bool ValidateReplaceToAttribute(UnityEditor.MenuCommand command)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
return command.context is TMP_InputField && !(command.context is XericUIrAttributeTextMeshProInputField);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/TMP_InputField/Replace To/Xeric (Attribute)", false, 10)]
|
||||
private static void ReplaceToAttribute(UnityEditor.MenuCommand command)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
var tmpComp = command.context as UnityEngine.Component;
|
||||
if (tmpComp != null)
|
||||
tmpComp.gameObject.AddComponent<XericUIrAttributeTextMeshProInputField>();
|
||||
#endif
|
||||
}
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/TMP_InputField/Replace To/Unity TMP_InputField", true)]
|
||||
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericUIrAttributeTextMeshProInputField;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/TMP_InputField/Replace To/Unity TMP_InputField", false, 100)]
|
||||
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
{
|
||||
var comp = command.context as XericUIrAttributeTextMeshProInputField;
|
||||
if (comp != null)
|
||||
UnityEngine.Object.DestroyImmediate(comp);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb8f3a8825c4b06458021d0414b254cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,94 +0,0 @@
|
||||
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/Xeric (Attribute)", 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/Xeric (Attribute)", 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/Unity TextMeshPro", true)]
|
||||
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericUIrAttributeTextMeshProText;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/TextMeshProUGUI/Replace To/Unity TextMeshPro", false, 100)]
|
||||
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
{
|
||||
var comp = command.context as XericUIrAttributeTextMeshProText;
|
||||
if (comp != null)
|
||||
UnityEngine.Object.DestroyImmediate(comp);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd08262713d01a24bb929ead3cc680ab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,64 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XericUI.Helper;
|
||||
using XericUI.ReflectionUIGenerator;
|
||||
|
||||
namespace XericUI.OverrideUI
|
||||
{
|
||||
/// <summary>
|
||||
/// 带字段标记的增强开关组件
|
||||
/// 继承 XericToggle,额外支持 XuiavrgFieldTag 标记,便于反射界面生成器自动绑定
|
||||
/// </summary>
|
||||
[AddComponentMenu("Xeric UI Vessel/Attribute/Toggle", 32)]
|
||||
public class XericUIrAttributeToggle : XericToggle, IXuiavrgFieldTagProvider
|
||||
{
|
||||
[SerializeField]
|
||||
[Tooltip("Entry 功能标记,用于自动绑定匹配")]
|
||||
private XuiavrgFieldTag _entryTag = XuiavrgFieldTag.Toggle;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("同一 Tag 存在多个时的索引区分")]
|
||||
private int _tagIndex = 0;
|
||||
|
||||
public XuiavrgFieldTag EntryTag => _entryTag;
|
||||
public int TagIndex => _tagIndex;
|
||||
|
||||
#region 组件替换
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Xeric (Attribute)", true)]
|
||||
private static bool ValidateReplaceToAttribute(UnityEditor.MenuCommand command)
|
||||
=> command.context is Toggle and not XericUIrAttributeToggle;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Xeric (Attribute)", false, 12)]
|
||||
private static void ReplaceToAttribute(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<Toggle, XericUIrAttributeToggle,
|
||||
(Graphic graphic, ToggleGroup group, Toggle.ToggleEvent onValueChanged)>(
|
||||
o => (o.graphic, o.group, o.onValueChanged),
|
||||
(t, d) =>
|
||||
{
|
||||
t.graphic = d.graphic;
|
||||
t.group = d.group;
|
||||
t.onValueChanged = d.onValueChanged;
|
||||
});
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Unity Toggle (Attribute)", true)]
|
||||
private static bool ValidateReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.context is XericUIrAttributeToggle;
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/Toggle/Replace To/Unity Toggle (Attribute)", false, 100)]
|
||||
private static void ReplaceToUnity(UnityEditor.MenuCommand command)
|
||||
=> command.ReplaceCommandContext<XericUIrAttributeToggle, Toggle,
|
||||
(Graphic graphic, ToggleGroup group, Toggle.ToggleEvent onValueChanged)>(
|
||||
o => (o.graphic, o.group, o.onValueChanged),
|
||||
(t, d) =>
|
||||
{
|
||||
t.graphic = d.graphic;
|
||||
t.group = d.group;
|
||||
t.onValueChanged = d.onValueChanged;
|
||||
});
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c20b871bced43a34a89dd5a7cf05c90b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XericUI.ReflectionUIGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// MDVM 编组容器脚本
|
||||
/// 管理 GroupPath 对应的编组容器,容纳子 UI 组件
|
||||
///
|
||||
/// 外部组件挂载后尺寸由父级影响
|
||||
/// 内部子元素通过锚点系统获得布局
|
||||
/// 可通过挂载 TMP_Text / Image 等组件实现组标题/背景装饰
|
||||
/// </summary>
|
||||
[AddComponentMenu("Xeric Library/UI Action Vessel/XuiAvrgMDGroup")]
|
||||
public class XuiAvrgMDGroup : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
[Tooltip("编组路径,对应元数据的 GroupPath")]
|
||||
private string _groupName;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("编组排序值,越小越靠前")]
|
||||
private int _groupOrder;
|
||||
|
||||
/// <summary>内容挂载点 — 子 UI 组件应放入此 Transform</summary>
|
||||
public Transform contentRoot;
|
||||
|
||||
/// <summary>编组路径对应的组名</summary>
|
||||
public string GroupName => _groupName;
|
||||
|
||||
/// <summary>编组排序值</summary>
|
||||
public int GroupOrder => _groupOrder;
|
||||
|
||||
/// <summary>上下文层级深度(如 "group1/subgroup" → depth=2)</summary>
|
||||
public int ContextDepth { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 初始化编组容器
|
||||
/// </summary>
|
||||
public void Initialize(string groupPath, int order)
|
||||
{
|
||||
_groupName = groupPath;
|
||||
_groupOrder = order;
|
||||
ContextDepth = string.IsNullOrEmpty(groupPath) ? 0 : groupPath.Split('/').Length;
|
||||
|
||||
gameObject.name = $"Group [{groupPath}]";
|
||||
|
||||
// 如果没有指定 contentRoot,自动使用自身作为挂载点
|
||||
if (contentRoot == null)
|
||||
contentRoot = transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 263e829bad1c50d469036934e671aaa8
|
||||
guid: 28ce72a98719bc740aef7059228f741e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
Reference in New Issue
Block a user