Skip to content

Commit 4cf9ea1

Browse files
Add support for private methods
1 parent 07c8cf2 commit 4cf9ea1

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

Assets/CustomMethodButton/Drawers/MethodButtonAttributeDrawer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using UnityEngine;
22
using UnityEditor;
3+
using System.Reflection;
34

45
[CustomPropertyDrawer(typeof(MethodButtonAttribute))]
56
public class MethodButtonAttributeDrawer : PropertyDrawer
@@ -43,7 +44,7 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent
4344
private void InvokeMethod(SerializedProperty property, string name)
4445
{
4546
Object target = property.serializedObject.targetObject;
46-
target.GetType().GetMethod(name).Invoke(target, null);
47+
target.GetType().GetMethod(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly).Invoke(target, null);
4748
}
4849

4950
private void LogErrorMessage(SerializedProperty editorFoldout)

Assets/Demo/Scripts/ExampleClass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public void DoAnotherThing()
1313
{
1414
Debug.Log("That other thing be did.");
1515
}
16-
public void DoAThirdThing()
16+
private void DoAThirdThing()
1717
{
1818
Debug.Log("That third thing be did.");
1919
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ExampleClass : MonoBehaviour
2424
{
2525
Debug.Log("That other thing be did.");
2626
}
27-
public void DoAThirdThing()
27+
private void DoAThirdThing()
2828
{
2929
Debug.Log("That third thing be did.");
3030
}

0 commit comments

Comments
 (0)