input相关
This commit is contained in:
@@ -1,27 +1,143 @@
|
||||
namespace NBF
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class InputDef
|
||||
{
|
||||
public class UI
|
||||
{
|
||||
public static Dictionary<string, List<string>> Icons = new Dictionary<string, List<string>>();
|
||||
|
||||
[InputIcon("icon_controller_123", "icon_controller_2")]
|
||||
public const string Back = "Back";
|
||||
|
||||
[InputIcon("icon_controller_129", "icon_controller_1")]
|
||||
public const string Enter = "Enter";
|
||||
|
||||
[InputIcon("icon_controller_127", "icon_controller_19")]
|
||||
public const string Tab = "Tab";
|
||||
|
||||
[InputIcon("icon_controller_29", "icon_controller_89")]
|
||||
public const string Prev = "Prev";
|
||||
|
||||
[InputIcon("icon_controller_30", "icon_controller_77")]
|
||||
public const string Next = "Next";
|
||||
|
||||
[InputIcon("icon_controller_98", "icon_controller_27")]
|
||||
public const string SubPrev = "SubPrev";
|
||||
|
||||
[InputIcon("icon_controller_75", " icon_controller_28")]
|
||||
public const string SubNext = "SubNext";
|
||||
public const string Left = "Left";
|
||||
public const string Right = "Right";
|
||||
public const string Up = "Up";
|
||||
public const string Down = "Down";
|
||||
|
||||
[InputIcon("", "")] public const string Left = "Left";
|
||||
[InputIcon("", "")] public const string Right = "Right";
|
||||
[InputIcon("", "")] public const string Up = "Up";
|
||||
[InputIcon("", "")] public const string Down = "Down";
|
||||
}
|
||||
|
||||
public class Player
|
||||
public static class Player
|
||||
{
|
||||
public static Dictionary<string, List<string>> Icons = new Dictionary<string, List<string>>();
|
||||
public const string Run = "Run";
|
||||
public const string Use1 = "Use1";
|
||||
public const string Use2 = "Use2";
|
||||
}
|
||||
|
||||
#region Load Icon
|
||||
|
||||
public static void LoadIcon()
|
||||
{
|
||||
// 获取InputDef类型
|
||||
Type inputDefType = typeof(NBF.InputDef);
|
||||
|
||||
// 检查UI类
|
||||
Type uiType = inputDefType.GetNestedType("UI");
|
||||
if (uiType != null)
|
||||
{
|
||||
var uiFields = GetInputIconFieldsFromType(uiType);
|
||||
if (uiFields.Count > 0)
|
||||
{
|
||||
foreach (var field in uiFields)
|
||||
{
|
||||
InputIconAttribute attribute =
|
||||
(InputIconAttribute)Attribute.GetCustomAttribute(field, typeof(InputIconAttribute));
|
||||
|
||||
string value = (string)field.GetValue(null); // 获取常量值
|
||||
if (attribute != null)
|
||||
{
|
||||
List<string> icons = new List<string>
|
||||
{
|
||||
attribute.KeyBoardIcon,
|
||||
attribute.ControllerIcon
|
||||
};
|
||||
UI.Icons[value] = icons;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检查Player类
|
||||
Type playerType = inputDefType.GetNestedType("Player");
|
||||
if (playerType != null)
|
||||
{
|
||||
var playerFields = GetInputIconFieldsFromType(playerType);
|
||||
if (playerFields.Count > 0)
|
||||
{
|
||||
foreach (var field in playerFields)
|
||||
{
|
||||
InputIconAttribute attribute =
|
||||
(InputIconAttribute)Attribute.GetCustomAttribute(field, typeof(InputIconAttribute));
|
||||
|
||||
string value = (string)field.GetValue(null); // 获取常量值
|
||||
if (attribute != null)
|
||||
{
|
||||
List<string> icons = new List<string>
|
||||
{
|
||||
attribute.KeyBoardIcon,
|
||||
attribute.ControllerIcon
|
||||
};
|
||||
Player.Icons[value] = icons;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// foreach (var key in InputDef.UI.Icons.Keys)
|
||||
// {
|
||||
// var icons = InputDef.UI.Icons[key];
|
||||
// Log.Error($"KEY={key} icon={string.Join(",", icons)}");
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
// 从特定类型获取带有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;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user