调整目录结构
This commit is contained in:
66
Assets/Scripts/Model/Common/Attrobites/AttributeHelper.cs
Normal file
66
Assets/Scripts/Model/Common/Attrobites/AttributeHelper.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public static class AttributeHelper
|
||||
{
|
||||
// 获取特定嵌套类中带有InputIconAttribute的常量字段
|
||||
public static Dictionary<string, List<FieldInfo>> GetNestedClassInputIconFields()
|
||||
{
|
||||
var result = new Dictionary<string, List<FieldInfo>>();
|
||||
|
||||
// 获取InputDef类型
|
||||
Type inputDefType = typeof(NBF.InputDef);
|
||||
|
||||
// 检查UI类
|
||||
Type uiType = inputDefType.GetNestedType("UI");
|
||||
if (uiType != null)
|
||||
{
|
||||
var uiFields = GetInputIconFieldsFromType(uiType);
|
||||
if (uiFields.Count > 0)
|
||||
{
|
||||
result.Add("UI", uiFields);
|
||||
}
|
||||
}
|
||||
|
||||
// 检查Player类
|
||||
Type playerType = inputDefType.GetNestedType("Player");
|
||||
if (playerType != null)
|
||||
{
|
||||
var playerFields = GetInputIconFieldsFromType(playerType);
|
||||
if (playerFields.Count > 0)
|
||||
{
|
||||
result.Add("Player", playerFields);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// 从特定类型获取带有InputIconAttribute的常量字段
|
||||
private static List<FieldInfo> GetInputIconFieldsFromType(Type type)
|
||||
{
|
||||
List<FieldInfo> result = new List<FieldInfo>();
|
||||
|
||||
// 只获取公共常量字段
|
||||
FieldInfo[] fields = type.GetFields(
|
||||
BindingFlags.Public |
|
||||
BindingFlags.Static |
|
||||
BindingFlags.FlattenHierarchy);
|
||||
|
||||
foreach (FieldInfo field in fields)
|
||||
{
|
||||
// 检查是否是常量且带有InputIconAttribute
|
||||
if (field.IsLiteral && !field.IsInitOnly &&
|
||||
Attribute.IsDefined(field, typeof(InputIconAttribute)))
|
||||
{
|
||||
result.Add(field);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa024ae7ea104f809ace6beff59c12d8
|
||||
timeCreated: 1748188551
|
||||
77
Assets/Scripts/Model/Common/Attrobites/Attributes.cs
Normal file
77
Assets/Scripts/Model/Common/Attrobites/Attributes.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public abstract class BaseAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class UIBindAttribute : BaseAttribute
|
||||
{
|
||||
public int Id;
|
||||
|
||||
public UIBindAttribute(int id)
|
||||
{
|
||||
this.Id = id;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class UIExtensionAutoBindAttribute : BaseAttribute
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class InputIconAttribute : BaseAttribute
|
||||
{
|
||||
public string KeyBoardIcon;
|
||||
public string ControllerIcon;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="keyBoardIcon">键盘图标</param>
|
||||
/// <param name="controllerIcon">控制器图标</param>
|
||||
public InputIconAttribute(string keyBoardIcon, string controllerIcon)
|
||||
{
|
||||
KeyBoardIcon = keyBoardIcon;
|
||||
ControllerIcon = controllerIcon;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Class, AllowMultiple = true)]
|
||||
public class TitleAttribute : BaseAttribute
|
||||
{
|
||||
public string Title;
|
||||
|
||||
public TitleAttribute(string title)
|
||||
{
|
||||
Title = title;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Class, AllowMultiple = true)]
|
||||
public class DescriptionAttribute : BaseAttribute
|
||||
{
|
||||
public string Description;
|
||||
|
||||
public DescriptionAttribute(string description)
|
||||
{
|
||||
Description = description;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Class, AllowMultiple = true)]
|
||||
public class SortAttribute : BaseAttribute
|
||||
{
|
||||
public int Sort;
|
||||
|
||||
public SortAttribute(int sort)
|
||||
{
|
||||
Sort = sort;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 647174a4726c4c4c92193aa7dcd3ddad
|
||||
timeCreated: 1748509835
|
||||
Reference in New Issue
Block a user