Add custom toolbar actions
Add custom buttons to the Asset Management toolbar in the Graph window.
Read time 1 minuteLast updated 23 days ago
Add custom buttons to the Asset Management toolbar in the Graph window.
You can add custom buttons to the Asset Management toolbar by creating toolbar element classes and applying the attribute.
[GraphToolbarElement]Prerequisites
You must have created and implemented a graph tool.
Create a toolbar element class
To create a toolbar element class, do the following:
-
Create a class that inherits from any(
VisualElementin the example below).EditorToolbarButton -
Apply theattribute to bind it to your
[GraphToolbarElement]type.Graph -
Implementto get a reference to the editor window. This lets you access the current graph from within the button's click handler.
IAccessContainerWindow
[GraphToolbarElement(id, typeof(MySimpleGraph), order: 200)] class MyCustomToolbarAction : EditorToolbarButton, IAccessContainerWindow { public const string id = "MyGraphTool/CustomAction"; public EditorWindow containerWindow { get; set; } public MyCustomToolbarAction() { text = "My Action"; tooltip = "Performs a custom action on the graph"; icon = EditorGUIUtility.IconContent("console.infoicon").image as Texture2D; clicked += OnClick; } void OnClick() { if (containerWindow is IGraphWindow graphWindow) UnityEngine.Debug.Log(graphWindow.Graph.Name); } } #endregion CustomToolbarAction}
When you open your graph asset, your custom buttons appear in the Asset Management toolbar at the position determined by their value.
order