Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ConditionMenuAttribute

Marks a static method as a contributor to the right-click contextual menu of a transition's condition list. Every time the menu opens, the decorated method is invoked with a ConditionMenuContext that exposes the condition under the cursor and lets the method append entries via MenuContext.AppendAction.
Read time 4 minutesLast updated 7 days ago

Definition

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]public sealed class ConditionMenuAttribute : Attribute

Remarks

The decorated method must be
static
, return
void
, and take a single ConditionMenuContext parameter, which also exposes the transition and the rule the condition list belongs to. The user is responsible for filtering on the clicked condition and deciding what to append.
The 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 clicked ICondition. It is the root group condition when the root row is clicked. It is
null
when the click doesn't land on any condition or group row. A condition defined by deriving from Condition or Condition<T> is passed as that derived type.

Examples

[ConditionMenu(typeof(MyStateMachine))]static void AppendNewItems(ConditionMenuContext context){ if (context.ClickedObject is ICondition condition) { context.AppendAction("Custom/Inspect", () => Debug.Log(condition)); }}

Constructors

Constructor

Description

ConditionMenuAttribute(System.Type)Initializes a new instance of the ConditionMenuAttribute class.

Properties

Property

Description

StateMachineTypeThe StateMachine subclass the handler is restricted to.

Inheritance

Inherited Members