input相关
This commit is contained in:
66
Assets/Scripts/Common/Attrobites/AttributeHelper.cs
Normal file
66
Assets/Scripts/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;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Common/Attrobites/AttributeHelper.cs.meta
Normal file
3
Assets/Scripts/Common/Attrobites/AttributeHelper.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa024ae7ea104f809ace6beff59c12d8
|
||||
timeCreated: 1748188551
|
||||
22
Assets/Scripts/Common/Attrobites/InputIconAttribute.cs
Normal file
22
Assets/Scripts/Common/Attrobites/InputIconAttribute.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class InputIconAttribute : Attribute
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fb17097160c43ee9840411aded17084
|
||||
timeCreated: 1748180773
|
||||
Reference in New Issue
Block a user