Inspector Button Pro
Introduction - [ProButton]
Create inspector buttons simply by adding [ProButton] before your methods.
- test different method parameters values directly from the inspector
- parameter types include : int, float, bool, string ...
- auto prints the return value of the function ( no need for Debug.Log )
- quickly call game specific methods like "Restart Level" , "Start Power Up" , "Switch To Next Level" to quickly test your game.
- supports all methods , including static methods
- it works for both MonoBehaviors + ScriptableObjects & their children.
Example:
- test different method parameters values directly from the inspector
- parameter types include : int, float, bool, string ...
- auto prints the return value of the function ( no need for Debug.Log )
- quickly call game specific methods like "Restart Level" , "Start Power Up" , "Switch To Next Level" to quickly test your game.
- supports all methods , including static methods
- it works for both MonoBehaviors + ScriptableObjects & their children.
Example:
using com.cyborgAssets.inspectorButtonPro;
public class FireworkScript: MonoBehaviour
{
[ProButton]
void PlayFireworks(int count)
{
//play fireworks
}
}
Namespace
to use [ProButton] or [ProPlayButton], simply import this namespace at the top of your script
using com.cyborgAssets.inspectorButtonPro;
Important Note:
by default, method parameters that appear in the inspector are temporary & their purpose is to quickly test different method inputs only. unity resets the values you set when:
- entering play mode
- code recompiles
- quitting scene
- entering play mode
- code recompiles
- quitting scene
Experimental : Serialized Version ( full version only )
if you want to save ( serialize ) the method parameters so they persist when you quit Unity, recompile code, or enter playmode, you can inherit ButtonMonoBehavior or ButtonScriptableObject.
- this simply allow your scripts to maintain the values of the method parameters & prevents Unity from resetting them on recompilation or scene exit or entering playmode.
Note: when you change a class from inherting MonoBehavior to inherting ButtonMonoBehavior
- Unity doesn't auto refresh the inspector to be serialized
- to fix this, simply deselect the game object then re-select it
- this simply allow your scripts to maintain the values of the method parameters & prevents Unity from resetting them on recompilation or scene exit or entering playmode.
Note: when you change a class from inherting MonoBehavior to inherting ButtonMonoBehavior
- Unity doesn't auto refresh the inspector to be serialized
- to fix this, simply deselect the game object then re-select it
[ProPlayButton] Attribute
use [ProPlayButton] attribute to show inspector buttons that only execute if the unity editor is playing.
- this prevents human errors, where you click something like "DestroyAllEnemies()" while the editor is not playing
- it prevents accidentally changing the scene data.
[ProPlayButton]
void DestroyAllEnemies( )
{
//destroy all enemies
}
- this prevents human errors, where you click something like "DestroyAllEnemies()" while the editor is not playing
- it prevents accidentally changing the scene data.
[ProPlayButton]
void DestroyAllEnemies( )
{
//destroy all enemies
}
Tip: Use Dedicated Test Methods if needed
if you:
1. don't want to inherit ButtonMonoBehavior
2. or you want to serialize parameters that the asset can't serialize ( like System.Object or arrays )
3. or to create test buttons with preset values
then create dedicated test methods.
Example:
1. don't want to inherit ButtonMonoBehavior
2. or you want to serialize parameters that the asset can't serialize ( like System.Object or arrays )
3. or to create test buttons with preset values
then create dedicated test methods.
Example:
static void HandleSystemObject(System.Object myObject)
{
Debug.LogFormat("Method with a systemObject is called !");
}
#if UNITY_EDITOR
[ProButton]
void Test_HandleSystemObject()
{
System.Object myObject = new System.Object();
HandleSystemObject(myObject);
}
#endif
Loved it ?
then you will love our other assets :
Special use-case : Disabling the custom editor
if for any reason you want to temporarily disable the custom editor, simply comment the following line:
[CustomEditor (typeof (MonoBehaviour), true), CanEditMultipleObjects]
in the following classes:
* MonoBehaviourEditor.cs
* ProMonoBehaviourEditor.cs
* ScriptableObjectEditor.cs
* ProScriptableObjectEditor.cs
[CustomEditor (typeof (MonoBehaviour), true), CanEditMultipleObjects]
in the following classes:
* MonoBehaviourEditor.cs
* ProMonoBehaviourEditor.cs
* ScriptableObjectEditor.cs
* ProScriptableObjectEditor.cs