Skip to content

Commit

Permalink
Merge pull request cocos#2950 from MrcSnm/patch-3
Browse files Browse the repository at this point in the history
Adds dynamic visibility on inspector to documentation
  • Loading branch information
MrKylinGithub authored Jul 10, 2024
2 parents bf38e87 + 713fc6d commit df7f01d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
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.

0 comments on commit df7f01d

Please sign in to comment.