https://github.com/glasstoestudio/unitymethodbuttonattribute
Add this attribute to your class to create buttons in the inspector for selected methods. No need for a custom editor.
https://github.com/glasstoestudio/unitymethodbuttonattribute
unity unity-asset unity-editor unity-scripts unity2018 unity2d unity3d unity3d-plugin
Last synced: 3 months ago
JSON representation
Add this attribute to your class to create buttons in the inspector for selected methods. No need for a custom editor.
- Host: GitHub
- URL: https://github.com/glasstoestudio/unitymethodbuttonattribute
- Owner: GlassToeStudio
- License: mit
- Created: 2019-02-17T21:36:19.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-07T01:36:06.000Z (almost 7 years ago)
- Last Synced: 2025-05-06T20:12:50.665Z (about 1 year ago)
- Topics: unity, unity-asset, unity-editor, unity-scripts, unity2018, unity2d, unity3d, unity3d-plugin
- Language: C#
- Size: 134 KB
- Stars: 13
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Unity MethodButton Attribute
Add this attribute to your class to create buttons in the inspector for selected methods. No need for a custom editor.
# Usage:
```cs
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
public int ExampleInt;
public bool ExampleBool;
internal void ExampleInternalMethod()
{
Debug.Log("Invoking: ExampleClass.ExampleInternalMethod");
}
public void ExamplePublicMethod()
{
Debug.Log("Invoking: ExampleClass.ExamplePublicMethod");
}
private void ExamplePrivateMethod()
{
Debug.Log("Invoking: ExampleClass.ExamplePrivateMethod");
}
protected void ExampleProtectedMethod()
{
Debug.Log("Invoking: ExampleClass.ExampleProtectedMethod");
}
/* Add these four lines of code to your class.
* Edit, add/remove, method names to the attribute.
* Names must match the method name passed into the attribute.
*
* The bool "editorFoldout" is used not only as the property that Unity will use to find the attribute,
* but also as the bool for the foldout in the editor.
*
* The #if UNITY_EDITOR preprocessor directive is so that this code is not compiled into the finished build.
* So no need to remvoe it prior to building.
*/
#if UNITY_EDITOR
[MethodButton("ExampleInternalMethod", "ExamplePublicMethod", "ExamplePrivateMethod", "ExampleProtectedMethod")]
[SerializeField] private bool editorFoldout;
#endif
}
```