Skip to content

Commit

Permalink
✨ 更新
Browse files Browse the repository at this point in the history
  • Loading branch information
xinansky committed Jun 8, 2024
1 parent 5ecb0d0 commit 14e199d
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions Editor.GUI.CLI/External/AIO.Graph/Window/GraphicEnum/GraphicEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,18 @@ public partial class GraphicEnum : GraphicRect
/// </summary>
public bool ShowName;

static GraphicEnum()
{
Data = new Dictionary<int, EnumInfo>();
}
static GraphicEnum() { Data = new Dictionary<int, EnumInfo>(); }

/// <summary>
/// 获取描述信息
/// </summary>
public static Dictionary<T, string> GetDescription<T>()
where T : struct, Enum
where T : struct, Enum
{
var type = typeof(T);
var type = typeof(T);
var DescriptionDic = new Dictionary<T, string>();
var index = 0;
var values = Enum.GetValues(type);
var index = 0;
var values = Enum.GetValues(type);
foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Static))
{
var attribute = field.GetCustomAttribute(typeof(DescriptionAttribute), false);
Expand All @@ -67,8 +64,8 @@ public static Dictionary<T, string> GetDescription<T>()
public static Dictionary<object, string> GetDescription(in Type type)
{
var DescriptionDic = new Dictionary<object, string>();
var index = 0;
var values = Enum.GetValues(type);
var index = 0;
var values = Enum.GetValues(type);
foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Static))
{
var attribute = field.GetCustomAttribute(typeof(DescriptionAttribute), false);
Expand All @@ -83,24 +80,18 @@ public static Dictionary<object, string> GetDescription(in Type type)
/// <summary>
/// 获取值
/// </summary>
public T GetValue<T>()
{
return (T)EnumValue;
}
public T GetValue<T>() { return (T)EnumValue; }

/// <summary>
/// 获取值
/// </summary>
public object GetValue(in Type type)
{
return Enum.Parse(type, EnumValue.ToString());
}
public object GetValue(in Type type) { return Enum.Parse(type, EnumValue.ToString()); }

/// <summary>
/// 更新
/// </summary>
public GraphicEnum Update<T>(in T type)
where T : struct, Enum
where T : struct, Enum
{
return Update(type, false, false);
}
Expand All @@ -109,20 +100,20 @@ public GraphicEnum Update<T>(in T type)
/// 更新
/// </summary>
public GraphicEnum Update<T>(in T type, in bool showName, in bool multipleChoice)
where T : struct, Enum
where T : struct, Enum
{
ShowName = showName;
ShowName = showName;
MultipleChoice = multipleChoice;
EnumValue = type;
Info = EnumInfo.Create<T>();
EnumValue = type;
Info = EnumInfo.Create<T>();
menu = new GenericMenu
{
allowDuplicateNames = false
};
foreach (var description in Info.DescriptionDic)
menu.AddItem(new GUIContent(description.Value),
EnumValue.GetHashCode() == description.Key.GetHashCode(),
() => EnumValue = description.Key);
EnumValue.GetHashCode() == description.Key.GetHashCode(),
() => EnumValue = description.Key);

return this;
}
Expand All @@ -131,7 +122,7 @@ public GraphicEnum Update<T>(in T type, in bool showName, in bool multipleChoice
/// 更新
/// </summary>
public GraphicEnum Update<T>(in T type, in bool showName)
where T : struct, Enum
where T : struct, Enum
{
return Update(type, showName, false);
}
Expand Down

0 comments on commit 14e199d

Please sign in to comment.