Skip to content

Commit

Permalink
使用特性标记的方法名
Browse files Browse the repository at this point in the history
  • Loading branch information
KumoKyaku committed Jan 27, 2024
1 parent fa47ace commit 9c1b818
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -471,16 +471,18 @@ public static string MethodParameterDisplayName(ParameterInfo parameterInfo, boo
return parameterTypeDisplayName + " " + parameterInfo.Name;
}

public static string MethodDisplayName(MethodInfo method)
public static string MethodDisplayName(MethodInfo method, Attribute drawAttribute)
{
string editorButtonName = "";
bool useTypeFullName = false;
if (Attribute.IsDefined(method, typeof(ButtonAttribute)))
if (drawAttribute is ButtonAttribute buttonAttribute)
{
ButtonAttribute tmp =
(ButtonAttribute)Attribute.GetCustomAttribute(method, typeof(ButtonAttribute));
editorButtonName = tmp.ButtonName;
useTypeFullName = tmp.UseTypeFullName;
editorButtonName = buttonAttribute.ButtonName;
useTypeFullName = buttonAttribute.UseTypeFullName;
}
else if (drawAttribute is ContextMenu contextMenu)
{
editorButtonName = contextMenu.menuItem;
}

if (string.IsNullOrEmpty(editorButtonName))
Expand Down Expand Up @@ -523,18 +525,19 @@ public static string MethodUID(MethodInfo method)
return sb.ToString();
}

[Obsolete("", true)]
public static void DrawButtonforMethod(Object target,
MethodInfo methodInfo,
EditorButtonState state,
bool onlyPlaying)
{
DrawButtonforMethod(target, methodInfo, state, onlyPlaying ? 1 : 0);
DrawButtonforMethod(target, methodInfo, null, state, onlyPlaying ? 1 : 0);
}

public static void DrawButtonforMethod(Object target,
DrawMethod drawMethod)
{
DrawButtonforMethod(target, drawMethod.Method, drawMethod.State, drawMethod.EnableMode, drawMethod);
DrawButtonforMethod(target, drawMethod.Method, drawMethod.Attribute, drawMethod.State, drawMethod.EnableMode, drawMethod);
}

/// <summary>
Expand All @@ -550,6 +553,7 @@ public static void DrawButtonforMethod(Object target,
/// </param>
public static void DrawButtonforMethod(Object target,
MethodInfo methodInfo,
Attribute drawAttribute,
EditorButtonState state,
int enableMode = 0,
DrawMethod drawMethod = null)
Expand Down Expand Up @@ -586,7 +590,7 @@ public static void DrawButtonforMethod(Object target,
EditorGUI.BeginDisabledGroup(!enable);

//绘制按钮
string buttonName = MethodDisplayName(methodInfo);
string buttonName = MethodDisplayName(methodInfo, drawAttribute);
GUIContent button = new GUIContent(buttonName);
button.tooltip = drawMethod?.Tooltip?.tooltip;
bool clicked = GUILayout.Button(button, GUILayout.ExpandWidth(true));
Expand Down

0 comments on commit 9c1b818

Please sign in to comment.