Skip to content

Commit

Permalink
Refine visible modifier behavior for uuid, name, enabled on nodes and…
Browse files Browse the repository at this point in the history
… components (cocos#15671)

* 完善 uuid 与 node 的 visible 修饰器行为

* refine code

* refine code
  • Loading branch information
knoxHuang authored Jul 17, 2023
1 parent edcbce0 commit 8e0e500
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
7 changes: 7 additions & 0 deletions cocos/physics/framework/components/rigid-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
visible,
type,
serializable,
override,
} from 'cc.decorator';
import { DEBUG } from 'internal:constants';
import { Vec3, error, warn } from '../../../core';
Expand Down Expand Up @@ -68,6 +69,12 @@ export class RigidBody extends Component {

/// PUBLIC PROPERTY GETTER\SETTER ///

@override
@visible(false)
get enabled() {
return this._enabled;
}

/**
* @en
* Gets or sets the group of the rigid body.
Expand Down
4 changes: 3 additions & 1 deletion cocos/scene-graph/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
THE SOFTWARE.
*/

import { ccclass, tooltip, displayName, type, serializable, disallowAnimation } from 'cc.decorator';
import { ccclass, tooltip, displayName, type, serializable, disallowAnimation, visible } from 'cc.decorator';
import { EDITOR, TEST } from 'internal:constants';
import { Script } from '../asset/assets/scripts';
import { CCObject } from '../core/data/object';
Expand Down Expand Up @@ -98,6 +98,7 @@ class Component extends CCObject {
* log(comp.uuid);
* ```
*/
@visible(false)
get uuid (): string {
return this._id;
}
Expand All @@ -122,6 +123,7 @@ class Component extends CCObject {
* log(comp.enabled);
* ```
*/
@visible(true)
get enabled (): boolean {
return this._enabled;
}
Expand Down
3 changes: 2 additions & 1 deletion cocos/scene-graph/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
THE SOFTWARE.
*/

import { ccclass, editable, serializable, type } from 'cc.decorator';
import { ccclass, editable, serializable, type, visible } from 'cc.decorator';
import { DEV, DEBUG, EDITOR, EDITOR_NOT_IN_PREVIEW } from 'internal:constants';
import { Layers } from './layers';
import { NodeUIProperties } from './node-ui-properties';
Expand Down Expand Up @@ -152,6 +152,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable {
* @zh 主要用于编辑器的 uuid,在编辑器下可用于持久化存储,在项目构建之后将变成自增的 id。
* @readOnly
*/
@visible(false)
get uuid (): string {
return this._id;
}
Expand Down
2 changes: 1 addition & 1 deletion editor/inspector/components/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports.$ = {
};

exports.update = function(dump) {
updatePropByDump(this, dump);
updatePropByDump(this, dump, ['name', 'enabled']);
};

exports.close = function() {
Expand Down
12 changes: 12 additions & 0 deletions editor/inspector/contributions/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,12 @@ const Elements = {
$active.invalid = false;
}

if (dump.value.enabled.visible === false) {
$active.setAttribute('hidden', '');
} else {
$active.removeAttribute('hidden');
}

const url = panel.getHelpUrl(dump.editor);
const $link = $section.querySelector('ui-link');
if (url) {
Expand Down Expand Up @@ -1258,6 +1264,12 @@ const Elements = {
$active.dispatch('confirm-dump');
});

if (component.value.enabled.visible === false) {
$active.setAttribute('hidden', '');
} else {
$active.removeAttribute('hidden');
}

const $link = $section.querySelector('.link');
const url = panel.getHelpUrl(component.editor);
if (url) {
Expand Down
6 changes: 5 additions & 1 deletion editor/inspector/utils/prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ exports.setHidden = function(data, element) {
}
};

exports.updatePropByDump = function(panel, dump) {
exports.updatePropByDump = function(panel, dump, ignores) {
panel.dump = dump;

if (!panel.elements) {
Expand All @@ -203,6 +203,10 @@ exports.updatePropByDump = function(panel, dump) {
const newPropKeys = [];

Object.keys(dump.value).forEach((key, index) => {
// 如果该属性在忽略列表中就不参与自动化渲染
if (Array.isArray(ignores) && ignores.includes(key)) {
return;
}
const info = dump.value[key];
if (!info.visible) {
return;
Expand Down

0 comments on commit 8e0e500

Please sign in to comment.