File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ # Unity MethodButton Attribute
2+
3+ Add this attribute to your class to create buttons in the inspector for selected methods. No need for a custom editor.
4+
5+ # Usage:
6+ ``` cs
7+ using UnityEngine ;
8+
9+ public class ExampleClass : MonoBehaviour
10+ {
11+ public int ExampleInt ;
12+ public bool ExampleBool ;
13+
14+ public void DoAThing ()
15+ {
16+ Debug .Log (" That thing be did." );
17+ }
18+ public void DoAnotherThing ()
19+ {
20+ Debug .Log (" That other thing be did." );
21+ }
22+ public void DoAThirdThing ()
23+ {
24+ Debug .Log (" That third thing be did." );
25+ }
26+
27+
28+ /* Add these four lines of code to your class.
29+ * Edit, add/remove, method names to the attribute.
30+ * Names must match the method name passed into the attribute.
31+ *
32+ * The bool "editorFoldout" is used not only as the property that Unity will use to find the attribute,
33+ * but also as the bool for the foldout in the editor.
34+ *
35+ * The #if UNITY_EDITOR preprocessor directive is so that this code is not compiled into the finished build.
36+ * So no need to remvoe it prior to building.
37+ */
38+
39+ #if UNITY_EDITOR
40+ [MethodButton (" DoAThing" , " DoAnotherThing" , " DoAThirdThing" )]
41+ [SerializeField ] private bool editorFoldout ;
42+ #endif
43+ }
44+
45+ ```
46+
47+
You can’t perform that action at this time.
0 commit comments