ClickCommand
[ClickCommand] is an Attribute that specifies the behavior when a VisualElement is clicked.
When declared in a View class, the SourceGenerator generates a Clickable from the declared ClickCommand.
Usage
You can use [ClickCommand] as follows:
csharp
[ClickCommand(ElementNames.Button)]
private void OnClick(EventBase evt)
{
UnityEngine.Debug.Log("Hello, ClickCommand!");
}Parameters
[ClickCommand] can specify the following parameters:
| Parameter | Type | Required | Default Value |
|---|---|---|---|
| TargetElementName | string | yes | - |
| ElementIndex | int | no | -1 |
| FindType | ElementFindType | no | ElementFindType.First |
- TargetElementName
Specifies whichVisualElementto construct the binding for. - ElementIndex
If there are multipleVisualElementswith the same name, specifies which one to target by index.
This parameter is ignored unlessFindTypeisElementFindType.Index. - FindType
Specifies how to search for theVisualElement.
See here for details.
Method Arguments
A method set with ClickCommand must have a single argument of type EventBase. EventBase allows you to receive events when there is interaction with the target VisualElement.