Version: Unity 6.6 Alpha (6000.6)
Language : English
Implement node options
Add subgraph support

Add custom toolbar actions

You can add custom buttons to the Asset Management toolbarA row of buttons and basic controls at the top of the Unity Editor that allows you to interact with the Editor in various ways (e.g. scaling, translation). More info
See in Glossary
by creating toolbar element classes and applying the [GraphToolbarElement] attribute.

Prerequisites

Implement a graph tool

Create a toolbar element class

  1. Create a class that inherits from EditorToolbarButton (or another toolbar element type), then:

  2. Apply the [GraphToolbarElement] attribute to bind it to your Graph type.

  3. Implement IAccessContainerWindow to get a reference to the editor window. This lets you access the current graph from within the button’s click handler.

[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);
    }
}

When you open your graph asset, your custom buttons appear in the Asset Management toolbar at the position determined by their order value.

Additional resources

Implement node options
Add subgraph support