Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds dynamic visibility on inspector to documentation #2950

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions versions/3.8/en/scripting/decorator.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,24 @@ To force hiding, set the `visible` attribute to `false`:
num = 0;
```

#### dynamic visibility
To set visibility dynamically, you must pass a function to it with the `this` argument and return a boolean:

```typescript
@ccclass('DynamicVisibilityExample')
export class DynamicVisibilityExample extends Component
{
@property(CCBoolean)
private isNumberAttributeVisible: boolean = true;

@property({visible(this: DynamicVisibilityExample){return this.isNumberAttributeVisible;}, type: CCInteger})
private myNumber: number = 500;
}
```

- When false ![Image showing before ticking the visibility](dynamic-visibility-0.png)
- When true ![Image showing after ticking the visibility](dynamic-visibility-1.png)

### `serializable` attribute

Properties are serialized by default. Once serialized, the property values set in the editor will be saved to the scene and other resource files, and will be automatically restored to the set property values when the scene is loaded. To not serialize, set `serializable` as false.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.