Skip to content

Commit

Permalink
Add docs about new Button attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
mafiesto4 committed Dec 6, 2024
1 parent eddb549 commit 5105ec4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
43 changes: 43 additions & 0 deletions manual/scripting/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,49 @@ The following table lists the most common attributes with usage description.
| **ReadOnly** | Properties and fields marked with this attribute won't be editable in the inspector. This allows to show object proeprties values in the editor but without option to modify the value which can be handy in some cases. |
| **Category** | Describes the category name for a type. Can be used to group script, asset or actor types for editor pickers to organize types. |
| **Watermark** | Adds a watermark to a string textbox in the editor field. |
| **Button** | Adds a button in the properties panel which user can click and invoke a method. |
## Button attribute
Button attributes can display methods as clickable buttons in the editor's properties panels. It works with both static and member methods in C++/C#/Visual Script.
# [C#](#tab/code-csharp)
```cs
/// <summary>
/// Button tooltip comes from this comment.
/// </summary>
[Button]
private void CallMe()
{
Debug.LogError("Ho!");
}
[Button("Another Button", "Custom tooltip text")]
public static void CallMeTest()
{
Debug.LogError("Hello there!");
}
```
# [C++](#tab/code-cpp)
```cpp
// Button tooltip comes from this comment.
API_FUNCTION(Attributes="Button")
void CallMe()
{
LOG(Error, "Ho!");
}

API_FUNCTION(Attributes="Button(\"Another Button\", \"Custom tooltip text\")")
static void CallMeTest()
{
LOG(Error, "Hello there!");
}
```
# [Visual Script](#tab/code-vs)
Right-click on a function node header, select *Edit attributes..** menu. Then add new `Button Attribute` and hit *OK* button.
![Button attribute in Visual Script](media/vs-button-attribute.png)
***
## Script execution in editor
Expand Down
17 changes: 17 additions & 0 deletions manual/scripting/custom-editors/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,23 @@ public int[] CoolVariable = new int[]

![Example](media/Collection.jpg)

### Button

Button attribute displays the method as a clickable button in the editor's properties panel.

```cs
/// <summary>
/// Button tooltip comes from this comment.
/// </summary>
[Button]
private void CallMe()
{
Debug.LogError("Ho!");
}
```

![Example](media/Button.png)

### CustomEditor

Overrides the default editor provided for the target object/class/field/property. Allows to extend visuals and editing experience of the object.
Expand Down
Binary file added manual/scripting/custom-editors/media/Button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added manual/scripting/media/vs-button-attribute.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5105ec4

Please sign in to comment.