Skip to content

Commit 86216be

Browse files
committed
Minor refactor changes & documentation update
1 parent d321e22 commit 86216be

4 files changed

Lines changed: 21 additions & 21 deletions

File tree

Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/EditorButtonAttributeDrawer.cs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ namespace Toolbox.Editor.Drawers
99
{
1010
public class EditorButtonAttributeDrawer : ToolboxDecoratorDrawer<EditorButtonAttribute>
1111
{
12-
private bool IsCoroutine(MethodInfo method)
13-
{
14-
return method.ReturnType == typeof(IEnumerator);
15-
}
16-
1712
private MethodInfo GetMethod(EditorButtonAttribute attribute, Object[] targetObjects, string methodName)
1813
{
1914
var methodInfo = ReflectionUtility.GetObjectMethod(methodName, targetObjects);
@@ -33,6 +28,11 @@ private MethodInfo GetMethod(EditorButtonAttribute attribute, Object[] targetObj
3328
return methodInfo;
3429
}
3530

31+
private static bool IsCoroutine(MethodInfo methodInfo)
32+
{
33+
return methodInfo.ReturnType == typeof(IEnumerator);
34+
}
35+
3636
private bool IsClickable(ButtonActivityType activityType)
3737
{
3838
switch (activityType)
@@ -58,7 +58,7 @@ private bool IsClickable(EditorButtonAttribute attribute, Object[] targetObjects
5858
}
5959

6060
var validateMethodName = attribute.ValidateMethodName;
61-
if (string.IsNullOrEmpty(validateMethodName))
61+
if (validateMethodName == null)
6262
{
6363
return true;
6464
}
@@ -84,8 +84,7 @@ private bool IsClickable(EditorButtonAttribute attribute, Object[] targetObjects
8484
continue;
8585
}
8686

87-
var result = (bool)validateMethodInfo.Invoke(target, null);
88-
if (!result)
87+
if (!(bool)validateMethodInfo.Invoke(target, null))
8988
{
9089
return false;
9190
}
@@ -96,19 +95,9 @@ private bool IsClickable(EditorButtonAttribute attribute, Object[] targetObjects
9695

9796
private void CallMethods(EditorButtonAttribute attribute, Object[] targetObjects)
9897
{
99-
var methodInfo = ReflectionUtility.GetObjectMethod(attribute.MethodName, targetObjects);
100-
//validate method name (check if method exists)
98+
var methodInfo = GetMethod(attribute, targetObjects, attribute.MethodName);
10199
if (methodInfo == null)
102100
{
103-
ToolboxEditorLog.AttributeUsageWarning(attribute, string.Format("{0} method not found.", attribute.MethodName));
104-
return;
105-
}
106-
107-
//validate parameters count and log warning
108-
var parameters = methodInfo.GetParameters();
109-
if (parameters.Length > 0)
110-
{
111-
ToolboxEditorLog.AttributeUsageWarning(attribute, string.Format("{0} method has to be parameterless.", attribute.MethodName));
112101
return;
113102
}
114103

Assets/Editor Toolbox/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,18 @@ public int var1;
313313
public int var1;
314314
```
315315
```csharp
316-
[EditorButton(nameof(MyMethod), "<b>My</b> Custom Label", activityType: ButtonActivityType.OnPlayMode)]
316+
[EditorButton(nameof(MyMethod), "<b>My</b> Custom Label", activityType: ButtonActivityType.OnPlayMode, ValidateMethodName = nameof(ValidationMethod))]
317317
public int var1;
318318

319319
private void MyMethod()
320320
{
321321
Debug.Log("MyMethod is invoked");
322322
}
323+
324+
private bool ValidationMethod()
325+
{
326+
return var1 == 0;
327+
}
323328
```
324329
```csharp
325330
[Highlight(0, 1, 0)]

Assets/Editor Toolbox/Runtime/Attributes/Toolbox/DecoratorAttributes/EditorButtonAttribute.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public EditorButtonAttribute(string methodName, string extraLabel = null, Button
2222
public string MethodName { get; private set; }
2323
/// <summary>
2424
/// If not <see langword="null"/> will be used to retrive validation method.
25+
/// Validation method will be used to disable/enable the button in the Inspector Window.
2526
/// </summary>
2627
public string ValidateMethodName { get; set; }
2728
public string ExtraLabel { get; private set; }

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,18 @@ public int var1;
313313
public int var1;
314314
```
315315
```csharp
316-
[EditorButton(nameof(MyMethod), "<b>My</b> Custom Label", activityType: ButtonActivityType.OnPlayMode)]
316+
[EditorButton(nameof(MyMethod), "<b>My</b> Custom Label", activityType: ButtonActivityType.OnPlayMode, ValidateMethodName = nameof(ValidationMethod))]
317317
public int var1;
318318

319319
private void MyMethod()
320320
{
321321
Debug.Log("MyMethod is invoked");
322322
}
323+
324+
private bool ValidationMethod()
325+
{
326+
return var1 == 0;
327+
}
323328
```
324329
```csharp
325330
[Highlight(0, 1, 0)]

0 commit comments

Comments
 (0)