重构反射生成属性界面

This commit is contained in:
2026-07-23 15:56:29 +08:00
parent c694115893
commit e63f1fb000
105 changed files with 2156 additions and 3280 deletions
@@ -1,7 +1,15 @@
namespace XericUI.ReflectionUIGenerator
namespace XericUI.ReflectionUIGenerator
{
/// <summary>
/// 反射 UI Attribute 标记接口
/// 所有标记 Attribute 实现此接口,在元数据提取阶段按序执行 BindMetaData
/// </summary>
public interface IXuiavrgAttribute
{
public void BindProperty(XuiavrgInspectorProperty property);
/// <summary>
/// 将 Attribute 的配置绑定到元数据对象
/// </summary>
/// <param name="metaData">目标元数据</param>
public void BindMetaData(AvrgMemberMetaData metaData);
}
}
}
@@ -1,75 +0,0 @@
using System;
namespace XericUI.ReflectionUIGenerator
{
/// <summary>
/// 反射属性标记
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class XuiavrgAttribute : Attribute, IXuiavrgAttribute
{
#region 字段属性
public readonly string LabelName;
public readonly string UIPropertyName;
public readonly string UnitLabelName;
public readonly int InspectorOrder;
public readonly string GroupName;
public readonly string OnTriggerCall;
public readonly XuiavrgSize ArgumentSize;
/// <summary>
/// 标记属性
/// </summary>
/// <param name="labelName">属性显示名称</param>
/// <param name="uiPropertyName">属性标记名(对应界面元素名称)</param>
/// <param name="unitLabelName">属性显示单位名称</param>
/// <param name="mustFillin">是否标记为必填项目</param>
/// <param name="inspectorOrder">属性显示顺序</param>
/// <param name="groupName">属性组名称(可以是以/&\分割的路径)</param>
/// <param name="onTriggerCall">属性附加的动作,调用此内联反射调用的函数</param>
/// <param name="size">属性组名称(可以是以/&\分割的路径)</param>
public XuiavrgAttribute(string labelName, string uiPropertyName, string unitLabelName,
int inspectorOrder = 0, string groupName = null, string onTriggerCall = "", XuiavrgSize size = XuiavrgSize.Normal)
{
LabelName = labelName;
UIPropertyName = uiPropertyName;
UnitLabelName = unitLabelName;
InspectorOrder = inspectorOrder;
GroupName = groupName;
OnTriggerCall = onTriggerCall;
ArgumentSize = size;
}
#endregion
#region 生成器
public void BindProperty(XuiavrgInspectorProperty property)
{
property.labelName = LabelName;
property.uiPropertyName = UIPropertyName;
property.unitLabelName = UnitLabelName;
property.inspectorOrder = InspectorOrder;
property.groupName = GroupName;
property.onTriggerCall = OnTriggerCall;
property.argumentSize = ArgumentSize;
}
#endregion
}
/// <summary>
/// 属性尺寸
/// </summary>
public enum XuiavrgSize
{
None = 0,
Tiny = 1000 - 2,
Small = 1000 - 1,
Normal = 1000,
Big,
Large,
}
}
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 10e270c86cab4817a0b8ce7877b2ab88
timeCreated: 1776505683
@@ -1,28 +0,0 @@
using System;
namespace XericUI.ReflectionUIGenerator
{
/// <summary>
/// 集合检查
/// </summary>
public class XuiavrgCollectionCheckAttribute : Attribute, IXuiavrgAttribute
{
public readonly int minCount;
public readonly int maxCount;
public readonly bool notEmpty;
public XuiavrgCollectionCheckAttribute(int minCount, int maxCount, bool notEmpty)
{
this.minCount = minCount;
this.maxCount = maxCount;
this.notEmpty = notEmpty;
}
public void BindProperty(XuiavrgInspectorProperty property)
{
property.collectionMinCount = minCount;
property.collectionMaxCount = maxCount;
property.collectionNotEmpty = notEmpty;
}
}
}
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 4ec4224cb3844c439dd5fdb6b31c9730
timeCreated: 1777363387
@@ -38,10 +38,11 @@ namespace XericUI.ReflectionUIGenerator
TagIndex = tagIndex;
}
public void BindProperty(XuiavrgInspectorProperty property)
public void BindMetaData(AvrgMemberMetaData metaData)
{
// 新的 Entry 体系通过 Manager.BuildEntries 直接处理此 Attribute
// 保留 IXuiavrgAttribute 兼容旧的 SchemaHydration 流程
metaData.GroupPath = GroupPath;
metaData.Tag = Tag;
metaData.TagIndex = TagIndex;
}
}
}
@@ -24,9 +24,9 @@ namespace XericUI.ReflectionUIGenerator
Order = order;
}
public void BindProperty(XuiavrgInspectorProperty property)
public void BindMetaData(AvrgMemberMetaData metaData)
{
property.inspectorOrder = Order;
metaData.FieldOrder = Order;
}
}
}
@@ -21,16 +21,16 @@ namespace XericUI.ReflectionUIGenerator
/// 创建预制体覆盖标记
/// </summary>
/// <param name="prefabGroupName">
/// 目标预制体组名称,与 XuiavrgPropertyGroupScriptableObject.groupName 匹配
/// 目标预制体名称,在 AvrgTypePrefabMappingConfig 中查找匹配
/// </param>
public XuiavrgFieldPrefabOverrideAttribute(string prefabGroupName)
{
PrefabGroupName = prefabGroupName;
}
public void BindProperty(XuiavrgInspectorProperty property)
public void BindMetaData(AvrgMemberMetaData metaData)
{
// 新的 Entry 体系通过 Manager 直接处理此 Attribute
metaData.PrefabOverrideName = PrefabGroupName;
}
}
}
@@ -1,5 +1,4 @@
using System;
using UnityEngine.Serialization;
using System;
namespace XericUI.ReflectionUIGenerator
{
@@ -20,9 +19,9 @@ namespace XericUI.ReflectionUIGenerator
Hide = hideInInspector;
}
public void BindProperty(XuiavrgInspectorProperty property)
public void BindMetaData(AvrgMemberMetaData metaData)
{
property.hideInInspector = Hide;
metaData.Hide = Hide;
}
}
}
}
@@ -1,15 +0,0 @@
using System;
namespace XericUI.ReflectionUIGenerator
{
/// <summary>
/// 不可为空
/// </summary>
public class XuiavrgNotEmptyAttribute : Attribute, IXuiavrgAttribute
{
public void BindProperty(XuiavrgInspectorProperty property)
{
property.notEmpty = true;
}
}
}
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 89e35e544d66421c8cc524d3b4d7b943
timeCreated: 1777360693
@@ -1,25 +0,0 @@
using System;
namespace XericUI.ReflectionUIGenerator
{
/// <summary>
/// 数值检查
/// </summary>
public class XuiavrgNumberCheckAttribute : Attribute, IXuiavrgAttribute
{
public readonly float minValue;
public readonly float maxValue;
public XuiavrgNumberCheckAttribute(float minValue, float maxValue)
{
this.minValue = minValue;
this.maxValue = maxValue;
}
public void BindProperty(XuiavrgInspectorProperty property)
{
property.numberMinValue = minValue;
property.numberMaxValue = maxValue;
}
}
}
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: d5b533c6d6ca4de8811adc3913d1fd9b
timeCreated: 1777362005
@@ -0,0 +1,61 @@
using System;
namespace XericUI.ReflectionUIGenerator
{
/// <summary>
/// 属性检查标记
/// 替代旧的 Required/NotEmpty 标记,扩展范围验证、警告、无效值检查
///
/// 使用示例:
/// [XuiavrgPropertyCheck(Required = true)] public string name;
/// [XuiavrgPropertyCheck(Required = true, ValidateReasonable = true)] public float speed;
/// [XuiavrgPropertyCheck(CheckKey = "MyCustomKey", ValidateWarning = true)] public int score;
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
public class XuiavrgPropertyCheckAttribute : Attribute, IXuiavrgAttribute
{
/// <summary>
/// 判断依据标识
/// 默认使用类型全称(如 "System.Single")与 AvrgValueRangeConfig 中的条目匹配
/// 也可自定义其他名称
/// </summary>
public string CheckKey { get; set; }
/// <summary>是否必填</summary>
public bool Required { get; set; }
/// <summary>是否启用合理值范围检查</summary>
public bool ValidateReasonable { get; set; }
/// <summary>是否启用警告状态检查</summary>
public bool ValidateWarning { get; set; }
/// <summary>是否启用无效值状态检查</summary>
public bool ValidateInvalid { get; set; }
public XuiavrgPropertyCheckAttribute()
{
}
/// <summary>
/// 创建必填检查标记
/// </summary>
public XuiavrgPropertyCheckAttribute(bool required)
{
Required = required;
}
public void BindMetaData(AvrgMemberMetaData metaData)
{
metaData.Required = Required;
// 如果指定了 CheckKey,使用它;否则保持元数据默认(元数据默认用 Type.FullName)
if (!string.IsNullOrEmpty(CheckKey))
metaData.PropertyCheckKey = CheckKey;
metaData.ValidateReasonable = ValidateReasonable;
metaData.ValidateWarning = ValidateWarning;
metaData.ValidateInvalid = ValidateInvalid;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 217e7cb9b7af5af4186e2d3f10a89c7c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,16 +0,0 @@
using System;
namespace XericUI.ReflectionUIGenerator
{
/// <summary>
/// 必填
/// </summary>
public class XuiavrgRequiredAttribute : Attribute, IXuiavrgAttribute
{
public void BindProperty(XuiavrgInspectorProperty property)
{
property.required = true;
property.notEmpty = true;
}
}
}
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: bcc4b8b735e84251b11ef87e9fe5b2cb
timeCreated: 1777358718
@@ -1,48 +0,0 @@
using System;
using UnityEngine;
namespace XericUI.ReflectionUIGenerator
{
/// <summary>
/// 字符串检查
/// </summary>
public class XuiavrgStringCheckAttribute : Attribute, IXuiavrgAttribute
{
public readonly int minLength;
public readonly int maxLength;
public readonly string regexPattern;
public readonly bool onlyLetters;
public readonly bool onlyNumber;
public readonly bool onlyEmail;
public readonly bool onlyPhone;
public readonly bool onlyUrl;
public XuiavrgStringCheckAttribute(
int minLength = 0, int maxLength = int.MaxValue,
string regexPattern = "",
bool onlyLetters = false, bool onlyNumber = false, bool onlyEmail = true, bool onlyPhone = true,
bool onlyUrl = true)
{
this.minLength = minLength;
this.maxLength = maxLength;
this.regexPattern = regexPattern;
this.onlyLetters = onlyLetters;
this.onlyNumber = onlyNumber;
this.onlyEmail = onlyEmail;
this.onlyPhone = onlyPhone;
this.onlyUrl = onlyUrl;
}
public void BindProperty(XuiavrgInspectorProperty property)
{
property.stringMinLength = minLength;
property.stringMaxLength = maxLength;
property.stringRegexPattern = regexPattern;
property.stringOnlyLetters = onlyLetters;
property.stringOnlyNumber = onlyNumber;
property.stringOnlyEmail = onlyEmail;
property.stringOnlyPhone = onlyPhone;
property.stringOnlyUrl = onlyUrl;
}
}
}
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 0a0e34665ed24a7c87e5eb84a45f6ef6
timeCreated: 1777360997