Reference
This page is dedicated for explaining scripting api references.
EditorActionButtonAttribute
an attribute class that is used for defining custom editor action buttons on static methods to draw them in component or object headers.
string
id
unique per type. There can be multiple id with same value on different targetTypes
Type
targetType
Show buttons on the target type and its derived types. If a type that derives from the target type is added separately with the same ID, the button will not be shown on that type and its derived types.
string
iconPath
path to an texture under the Assets/Editor Default Resources folder
e.g. "Assets/Editor Default Resource/SubFolder/example.png" only the bold part should be used.
string
tooltip
small message to show on hover
int
priority
button placement order
Use Case:
//Method can have both single parameter or array parameter.
//Array sends all selected contexts and single sends only the first from selected.
[EditorActionButton("print", typeof(Transform), "SubFolder/example.png",
"Print transform position", 0)]
private static void PrintTransform(Object context)
{
Debug.Log(((Transform)context).position);
}
//---------------or---------------
[EditorActionButton("print", typeof(Transform), "SubFolder/example.png",
"Print transform position", 0)]
private static void PrintTransform(Object[] contexts)
{
foreach(var context in contexts)
{
Debug.Log(((Transform)context).position);
}
}
EditorActionButtonValidateAttribute
Helper attribute for show/hide/disable condition management of the button
Type
targetType
Determines which type's buttons should be under validation
string
id
used to find editor action button with this id for validation
ButtonState
tells what to do with the button after validation
Use Case:
//Method can have both single parameter or array parameter.
//Array sends all selected contexts and single sends only the first from selected
[EditorActionButtonValidate(typeof(Transform),"print")]
private static ButtonState PrintTransform(Object context)
{
//Will hide button on rect transforms
return (context is RectTransform) ?
ButtonState.Hidden : ButtonState.Active;
}
//---------------or---------------
[EditorActionButtonValidate(typeof(Transform),"print")]
private static ButtonState PrintTransform(Object[] contexts)
{
//Will hide button on rect transforms
return (contexts.Any(ctx => ctx is RectTransform)) ?
ButtonState.Hidden : ButtonState.Active;
}
GameObjectActionButtonAttribute
an attribute class that is used for defining custom editor action buttons on static methods to draw them in inspector header or hierarchy item
string
id
unique per placementType. There can be multiple id with same value on different placementType
GOPlacementType
placementType
Determines which area the buttons should draw on
string
iconPath
path to an texture under the Assets/Editor Default Resources folder
e.g. "Assets/Editor Default Resource/SubFolder/example.png" only the bold part should be used.
string
tooltip
small message to show on hover
int
priority
button placement order
Use Case:
//Method can have both single parameter or array parameter.
//Array sends all selected contexts and single sends only the first from selected
[EditorActionButton("print", GOPlacementType.Header, "SubFolder/example.png",
"Print transform position", 0)]
private static void PrintComponentCount(GameObject context)
{
var components = context.GetComponent<Component>();
Debug.Log(components.Length);
}
//---------------or---------------
[EditorActionButton("print", GOPlacementType.Hierarchy, "SubFolder/example.png",
"Print transform position", 0)]
private static void PrintComponentCount(GameObject[] contexts)
{
foreach(GameObject context in contexts)
{
var components = context.GetComponent<Component>();
Debug.Log(components.Length);
}
}
GameObjectActionButtonValidateAttribute
Helper attribute for show/hide/disable condition management of the button
string
id
used to find game object action button with this id for validation
GOPlacementType
placementType
Determines which area the buttons should be validated on
Use Case:
//Method can have both single parameter or array parameter.
//Array sends all selected contexts and single sends only the first from selected
[GameObjectActionValidate("print", GOPlacementType.Header)]
private static ButtonState PrintComponentCount(GameObject context)
{
//Disable if target go is not a file asset
return EditorUtility.IsPersistent(context) ?
ButtonState.Disabled : ButtonState.Active;
}
//---------------or---------------
[GameObjectActionValidate("print", GOPlacementType.Header)]
private static void PrintComponentCount(GameObject[] contexts)
{
//Disable if target go is not a file asset
return context.All(ctx => EditorUtility.IsPersistent(ctx)) ?
ButtonState.Disabled : ButtonState.Active;
}
Last updated
Was this helpful?