StateMachineMenuAttribute
Marks a static method as a contributor to the state machine view's right-click contextual menu. Every time the menu opens, the decorated method is invoked with a StateMachineMenuContext that exposes the element under the cursor and lets the method append entries via MenuContext.AppendAction.
Read time 4 minutesLast updated 12 days ago
Definition
- Type: Class
- Namespace: Unity.GraphToolkit.Editor
- Assembly: UnityEditor
- Inherits from: Attribute
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]public sealed class StateMachineMenuAttribute : Attribute
Remarks
The decorated method must be , return , and take a single StateMachineMenuContext parameter. The user is responsible for filtering on the clicked element and deciding what to append.
staticvoidThe handler is invoked when the active state machine's type matches the listed type or derives from it. Apply the attribute multiple times on the same method to register it for several state machine types. MenuContext.ClickedObject is the element under the cursor: an IState, an ITransition or an IPort. A subgraph state is an ISubgraphState, which derives from IState. The value is when the click landed on empty space or on an element that is not exposed through the public API.
nullTo contribute entries to the graph view, use GraphMenuAttribute. For the blackboard, use BlackboardMenuAttribute. For the condition list of a transition inspector, use ConditionMenuAttribute.
Examples
[StateMachineMenu(typeof(MyStateMachine))]static void AppendStateMachineItems(StateMachineMenuContext context){ context.AppendAction("Custom/State Machine", () => Debug.Log(context.StateMachine)); if (context.ClickedObject is IState state) context.AppendAction("Custom/State", () => Debug.Log(state)); if (context.ClickedObject is ITransition transition) context.AppendAction("Custom/Transition", () => Debug.Log(transition));}
Constructors
Constructor | Description |
|---|---|
| StateMachineMenuAttribute(System.Type) | Initializes a new instance of the StateMachineMenuAttribute class. |
Properties
Property | Description |
|---|---|
| StateMachineType | The StateMachine subclass the handler is restricted to. |