From 1449fd1001f39839ab8ddfaaf4c457611d0521f0 Mon Sep 17 00:00:00 2001 From: DogeFu <609075410@qq.com> Date: Wed, 2 Aug 2023 14:13:15 +0800 Subject: [PATCH 1/7] refactor : prefab code optimization and protection --- cocos/scene-graph/node.jsb.ts | 24 +++++++-- cocos/scene-graph/node.ts | 4 ++ cocos/scene-graph/prefab/prefab-info.ts | 6 ++- cocos/scene-graph/prefab/utils.ts | 71 ++++++++++++++----------- 4 files changed, 68 insertions(+), 37 deletions(-) diff --git a/cocos/scene-graph/node.jsb.ts b/cocos/scene-graph/node.jsb.ts index 3f4308293ce..039e607b996 100644 --- a/cocos/scene-graph/node.jsb.ts +++ b/cocos/scene-graph/node.jsb.ts @@ -1214,11 +1214,25 @@ nodeProto[serializeTag] = function (serializationOutput: SerializationOutput, co // discard props disallow to synchronize const isRoot = this._prefab?.root === this; if (isRoot) { - serializationOutput.writeProperty('_objFlags', this._objFlags); - serializationOutput.writeProperty('_parent', this._parent); - serializationOutput.writeProperty('_prefab', this._prefab); - if (context.customArguments.keepNodeUuid) { - serializationOutput.writeProperty('_id', this._id); + // if B prefab is in A prefab,B can be referenced by component.We should discard it.because B is not the root of prefab + let isNestedPrefab = false; + let parent = this.getParent(); + while (parent) { + const nestedRoots = parent?._prefab?.nestedPrefabInstanceRoots; + if (nestedRoots && nestedRoots.length > 0) { + // if this node is not in nestedPrefabInstanceRoots,it means this node is not the root of prefab,so it should be discarded. + isNestedPrefab = !nestedRoots.some((root) => root === this); + break; + } + parent = parent.getParent(); + } + if (!isNestedPrefab) { + serializationOutput.writeProperty('_objFlags', this._objFlags); + serializationOutput.writeProperty('_parent', this._parent); + serializationOutput.writeProperty('_prefab', this._prefab); + if (context.customArguments.keepNodeUuid) { + serializationOutput.writeProperty('_id', this._id); + } } // TODO: editorExtrasTag may be a symbol in the future serializationOutput.writeProperty(editorExtrasTag, this[editorExtrasTag]); diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index aa7607d4aa1..12ac08369c3 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -363,6 +363,10 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { */ @serializable protected _prefab: PrefabInfo | null = null; + /** + * @engineInternal + */ + public get prefab (): PrefabInfo | null { return this._prefab; } protected _scene: Scene = null!; diff --git a/cocos/scene-graph/prefab/prefab-info.ts b/cocos/scene-graph/prefab/prefab-info.ts index f4427d7a04c..fe7b3bc7954 100644 --- a/cocos/scene-graph/prefab/prefab-info.ts +++ b/cocos/scene-graph/prefab/prefab-info.ts @@ -167,7 +167,7 @@ export class PrefabInstance { @type([TargetInfo]) public removedComponents: TargetInfo[] = []; - public targetMap: Record = {}; + public targetMap: TargetMap = new TargetMap(); /** * make sure prefab instance expand only once @@ -201,6 +201,10 @@ export class PrefabInstance { } } +export class TargetMap { + [key: string]: TargetMap | Node | Component; +} + @ccclass('cc.PrefabInfo') export class PrefabInfo { // the most top node of this prefab in the scene diff --git a/cocos/scene-graph/prefab/utils.ts b/cocos/scene-graph/prefab/utils.ts index 8e59d819bab..615aaa04cdb 100644 --- a/cocos/scene-graph/prefab/utils.ts +++ b/cocos/scene-graph/prefab/utils.ts @@ -27,7 +27,14 @@ import { EDITOR, SUPPORT_JIT } from 'internal:constants'; import { cclegacy, errorID, warn, editorExtrasTag } from '../../core'; import { Node } from '../node'; import { Component } from '../component'; -import { MountedChildrenInfo, PropertyOverrideInfo, MountedComponentsInfo, TargetInfo } from './prefab-info'; +import { + MountedChildrenInfo, + PropertyOverrideInfo, + MountedComponentsInfo, + TargetInfo, TargetMap, + PrefabInstance, + TargetOverrideInfo, +} from './prefab-info'; import { ValueType } from '../../core/value-types'; export * from './prefab-info'; @@ -35,7 +42,7 @@ export * from './prefab-info'; export function createNodeWithPrefab (node: Node): void { // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 - const prefabInfo = (node as any)._prefab; + const prefabInfo = node?.prefab; if (!prefabInfo) { return; } @@ -63,7 +70,6 @@ export function createNodeWithPrefab (node: Node): void { const _id = node.uuid; // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 - const _prefab = (node as any)._prefab; const editorExtras = node[editorExtrasTag]; // instantiate prefab @@ -92,14 +98,14 @@ export function createNodeWithPrefab (node: Node): void { // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 - if ((node as any)._prefab) { + if (node.prefab) { // just keep the instance - (node as any)._prefab.instance = _prefab?.instance; + node.prefab.instance = prefabInfo.instance; } } // TODO: more efficient id->Node/Component map -export function generateTargetMap (node: Node, targetMap: any, isRoot: boolean): void { +export function generateTargetMap (node: Node, targetMap: TargetMap, isRoot: boolean): void { if (!targetMap) { return; } @@ -112,15 +118,15 @@ export function generateTargetMap (node: Node, targetMap: any, isRoot: boolean): // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 - const prefabInstance = (node as any)._prefab?.instance; + const prefabInstance = node.prefab?.instance; if (!isRoot && prefabInstance) { - targetMap[prefabInstance.fileId] = {}; - curTargetMap = targetMap[prefabInstance.fileId]; + targetMap[prefabInstance.fileId] = new TargetMap(); + curTargetMap = targetMap[prefabInstance.fileId] as TargetMap; } // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 - const prefabInfo = (node as any)._prefab; + const prefabInfo = node.prefab; if (prefabInfo) { curTargetMap[prefabInfo.fileId] = node; } @@ -158,7 +164,7 @@ export function getTarget (localID: string[], targetMap: any): Node | Component return target; } -export function applyMountedChildren (node: Node, mountedChildren: MountedChildrenInfo[], targetMap: Record): void { +export function applyMountedChildren (node: Node, mountedChildren: MountedChildrenInfo[], targetMap: TargetMap): void { if (!mountedChildren) { return; } @@ -175,7 +181,7 @@ export function applyMountedChildren (node: Node, mountedChildren: MountedChildr const localID = childInfo.targetInfo.localID; if (localID.length > 0) { for (let i = 0; i < localID.length - 1; i++) { - curTargetMap = curTargetMap[localID[i]]; + curTargetMap = curTargetMap[localID[i]] as TargetMap; } } if (childInfo.nodes) { @@ -205,7 +211,7 @@ export function applyMountedChildren (node: Node, mountedChildren: MountedChildr } } -export function applyMountedComponents (node: Node, mountedComponents: MountedComponentsInfo[], targetMap: Record): void { +export function applyMountedComponents (node: Node, mountedComponents: MountedComponentsInfo[], targetMap: TargetMap): void { if (!mountedComponents) { return; } @@ -240,7 +246,7 @@ export function applyMountedComponents (node: Node, mountedComponents: MountedCo } } -export function applyRemovedComponents (node: Node, removedComponents: TargetInfo[], targetMap: Record): void { +export function applyRemovedComponents (node: Node, removedComponents: TargetInfo[], targetMap: TargetMap): void { if (!removedComponents) { return; } @@ -261,7 +267,7 @@ export function applyRemovedComponents (node: Node, removedComponents: TargetInf } } -export function applyPropertyOverrides (node: Node, propertyOverrides: PropertyOverrideInfo[], targetMap: Record): void { +export function applyPropertyOverrides (node: Node, propertyOverrides: PropertyOverrideInfo[], targetMap: TargetMap): void { if (propertyOverrides.length <= 0) { return; } @@ -322,7 +328,7 @@ export function applyPropertyOverrides (node: Node, propertyOverrides: PropertyO export function applyTargetOverrides (node: Node): void { // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 - const targetOverrides = (node as any)._prefab?.targetOverrides; + const targetOverrides = node.prefab?.targetOverrides as TargetOverrideInfo[]; if (targetOverrides) { for (let i = 0; i < targetOverrides.length; i++) { const targetOverride = targetOverrides[i]; @@ -330,8 +336,8 @@ export function applyTargetOverrides (node: Node): void { let source: Node | Component | null = targetOverride.source; const sourceInfo = targetOverride.sourceInfo; if (sourceInfo) { - // TODO: targetOverride.source is type of `Node | Component`, while `_prefab` does not exist on type 'Component'. - const sourceInstance = targetOverride.source?._prefab?.instance; + const src = targetOverride.source as Node; + const sourceInstance = src?.prefab?.instance; if (sourceInstance && sourceInstance.targetMap) { source = getTarget(sourceInfo.localID, sourceInstance.targetMap); } @@ -347,8 +353,8 @@ export function applyTargetOverrides (node: Node): void { if (!targetInfo) { continue; } - - const targetInstance = targetOverride.target?._prefab?.instance; + const targetAsNode = targetOverride.target as Node; + const targetInstance = targetAsNode?.prefab?.instance; if (!targetInstance || !targetInstance.targetMap) { continue; } @@ -387,20 +393,21 @@ export function applyTargetOverrides (node: Node): void { export function expandPrefabInstanceNode (node: Node, recursively = false): void { // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 - const prefabInfo = (node as any)._prefab; - const prefabInstance = prefabInfo?.instance; + const prefabInstance = node?.prefab?.instance as PrefabInstance; if (prefabInstance && !prefabInstance.expanded) { createNodeWithPrefab(node); // nested prefab should expand before parent(property override order) if (recursively) { if (node && node.children) { node.children.forEach((child) => { - expandPrefabInstanceNode(child, true); + if (child) { + expandPrefabInstanceNode(child, true); + } }); } } - const targetMap: Record = {}; + const targetMap = new TargetMap(); prefabInstance.targetMap = targetMap; generateTargetMap(node, targetMap, true); applyMountedChildren(node, prefabInstance.mountedChildren, targetMap); @@ -411,7 +418,9 @@ export function expandPrefabInstanceNode (node: Node, recursively = false): void } else if (recursively) { if (node && node.children) { node.children.forEach((child) => { - expandPrefabInstanceNode(child, true); + if (child) { + expandPrefabInstanceNode(child, true); + } }); } } @@ -420,15 +429,15 @@ export function expandPrefabInstanceNode (node: Node, recursively = false): void export function expandNestedPrefabInstanceNode (node: Node): void { // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 - const prefabInfo = (node as any)._prefab; + const prefabInfo = node.prefab; if (prefabInfo && prefabInfo.nestedPrefabInstanceRoots) { prefabInfo.nestedPrefabInstanceRoots.forEach((instanceNode: Node) => { - expandPrefabInstanceNode(instanceNode); + expandPrefabInstanceNode(instanceNode, true); // when expanding the prefab,it's children will be change,so need to apply after expanded - if (!EDITOR) { - applyNodeAndComponentId(instanceNode, (instanceNode as any)._prefab?.instance?.fileId ?? ''); - } + // if (!EDITOR) { + // applyNodeAndComponentId(instanceNode, (instanceNode as any)._prefab?.instance?.fileId ?? ''); + // } }); } } @@ -445,7 +454,7 @@ export function applyNodeAndComponentId (prefabInstanceNode: Node, rootId: strin const child = children[i]; // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 - const prefabInfo = (child as any)._prefab!; + const prefabInfo = child.prefab!; const fileId = prefabInfo?.instance ? prefabInfo.instance.fileId : prefabInfo?.fileId; if (!fileId) continue; child.id = `${rootId}${fileId}`; From aba0ff9e672247a85424aca91060bc271660ffa1 Mon Sep 17 00:00:00 2001 From: DogeFu <609075410@qq.com> Date: Wed, 2 Aug 2023 14:20:05 +0800 Subject: [PATCH 2/7] remove extra if --- cocos/scene-graph/prefab/utils.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cocos/scene-graph/prefab/utils.ts b/cocos/scene-graph/prefab/utils.ts index 615aaa04cdb..0e7d8274723 100644 --- a/cocos/scene-graph/prefab/utils.ts +++ b/cocos/scene-graph/prefab/utils.ts @@ -400,9 +400,7 @@ export function expandPrefabInstanceNode (node: Node, recursively = false): void if (recursively) { if (node && node.children) { node.children.forEach((child) => { - if (child) { - expandPrefabInstanceNode(child, true); - } + expandPrefabInstanceNode(child, true); }); } } @@ -418,9 +416,7 @@ export function expandPrefabInstanceNode (node: Node, recursively = false): void } else if (recursively) { if (node && node.children) { node.children.forEach((child) => { - if (child) { - expandPrefabInstanceNode(child, true); - } + expandPrefabInstanceNode(child, true); }); } } From 992e31f522e4cfa6c08e8328b6d046e55d154020 Mon Sep 17 00:00:00 2001 From: DogeFu <609075410@qq.com> Date: Wed, 2 Aug 2023 14:24:35 +0800 Subject: [PATCH 3/7] remove extra param --- cocos/scene-graph/prefab/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scene-graph/prefab/utils.ts b/cocos/scene-graph/prefab/utils.ts index 0e7d8274723..d383e8bf925 100644 --- a/cocos/scene-graph/prefab/utils.ts +++ b/cocos/scene-graph/prefab/utils.ts @@ -429,7 +429,7 @@ export function expandNestedPrefabInstanceNode (node: Node): void { if (prefabInfo && prefabInfo.nestedPrefabInstanceRoots) { prefabInfo.nestedPrefabInstanceRoots.forEach((instanceNode: Node) => { - expandPrefabInstanceNode(instanceNode, true); + expandPrefabInstanceNode(instanceNode); // when expanding the prefab,it's children will be change,so need to apply after expanded // if (!EDITOR) { // applyNodeAndComponentId(instanceNode, (instanceNode as any)._prefab?.instance?.fileId ?? ''); From 4262bdb91e395c68d162c077685859e351bac237 Mon Sep 17 00:00:00 2001 From: DogeFu <609075410@qq.com> Date: Wed, 2 Aug 2023 15:48:30 +0800 Subject: [PATCH 4/7] replace class with interface --- cocos/scene-graph/prefab/prefab-info.ts | 6 ++---- cocos/scene-graph/prefab/utils.ts | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cocos/scene-graph/prefab/prefab-info.ts b/cocos/scene-graph/prefab/prefab-info.ts index fe7b3bc7954..dac885a21aa 100644 --- a/cocos/scene-graph/prefab/prefab-info.ts +++ b/cocos/scene-graph/prefab/prefab-info.ts @@ -167,7 +167,7 @@ export class PrefabInstance { @type([TargetInfo]) public removedComponents: TargetInfo[] = []; - public targetMap: TargetMap = new TargetMap(); + public targetMap: TargetMap = {}; /** * make sure prefab instance expand only once @@ -201,9 +201,7 @@ export class PrefabInstance { } } -export class TargetMap { - [key: string]: TargetMap | Node | Component; -} +export interface TargetMap { [k: string]: TargetMap | Node | Component } @ccclass('cc.PrefabInfo') export class PrefabInfo { diff --git a/cocos/scene-graph/prefab/utils.ts b/cocos/scene-graph/prefab/utils.ts index d383e8bf925..c6d7481b842 100644 --- a/cocos/scene-graph/prefab/utils.ts +++ b/cocos/scene-graph/prefab/utils.ts @@ -120,7 +120,7 @@ export function generateTargetMap (node: Node, targetMap: TargetMap, isRoot: boo // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 const prefabInstance = node.prefab?.instance; if (!isRoot && prefabInstance) { - targetMap[prefabInstance.fileId] = new TargetMap(); + targetMap[prefabInstance.fileId] = {}; curTargetMap = targetMap[prefabInstance.fileId] as TargetMap; } @@ -405,7 +405,7 @@ export function expandPrefabInstanceNode (node: Node, recursively = false): void } } - const targetMap = new TargetMap(); + const targetMap = {}; prefabInstance.targetMap = targetMap; generateTargetMap(node, targetMap, true); applyMountedChildren(node, prefabInstance.mountedChildren, targetMap); From 992ee28b6710e5aac6409f571b39dcea51bba4b7 Mon Sep 17 00:00:00 2001 From: dogeFu <609075410@qq.com> Date: Wed, 2 Aug 2023 16:23:03 +0800 Subject: [PATCH 5/7] Update cocos/scene-graph/prefab/utils.ts Co-authored-by: PP --- cocos/scene-graph/prefab/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scene-graph/prefab/utils.ts b/cocos/scene-graph/prefab/utils.ts index c6d7481b842..18d26af769e 100644 --- a/cocos/scene-graph/prefab/utils.ts +++ b/cocos/scene-graph/prefab/utils.ts @@ -336,7 +336,7 @@ export function applyTargetOverrides (node: Node): void { let source: Node | Component | null = targetOverride.source; const sourceInfo = targetOverride.sourceInfo; if (sourceInfo) { - const src = targetOverride.source as Node; + const src = targetOverride.source as Node; const sourceInstance = src?.prefab?.instance; if (sourceInstance && sourceInstance.targetMap) { source = getTarget(sourceInfo.localID, sourceInstance.targetMap); From 3594748396e0f759891a501fd33a365c10950df5 Mon Sep 17 00:00:00 2001 From: DogeFu <609075410@qq.com> Date: Mon, 7 Aug 2023 18:05:18 +0800 Subject: [PATCH 6/7] remove command and protect access --- cocos/scene-graph/node.jsb.ts | 2 +- cocos/scene-graph/node.ts | 2 +- cocos/scene-graph/prefab/utils.ts | 14 -------------- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/cocos/scene-graph/node.jsb.ts b/cocos/scene-graph/node.jsb.ts index 039e607b996..22b9a73c5f4 100644 --- a/cocos/scene-graph/node.jsb.ts +++ b/cocos/scene-graph/node.jsb.ts @@ -1218,7 +1218,7 @@ nodeProto[serializeTag] = function (serializationOutput: SerializationOutput, co let isNestedPrefab = false; let parent = this.getParent(); while (parent) { - const nestedRoots = parent?._prefab?.nestedPrefabInstanceRoots; + const nestedRoots = parent._prefab?.nestedPrefabInstanceRoots; if (nestedRoots && nestedRoots.length > 0) { // if this node is not in nestedPrefabInstanceRoots,it means this node is not the root of prefab,so it should be discarded. isNestedPrefab = !nestedRoots.some((root) => root === this); diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index 12ac08369c3..c1724a27da3 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -1810,7 +1810,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { let isNestedPrefab = false; let parent = this.getParent(); while (parent) { - const nestedRoots = parent?._prefab?.nestedPrefabInstanceRoots; + const nestedRoots = parent._prefab?.nestedPrefabInstanceRoots; if (nestedRoots && nestedRoots.length > 0) { // if this node is not in nestedPrefabInstanceRoots,it means this node is not the root of prefab,so it should be discarded. isNestedPrefab = !nestedRoots.some((root) => root === this); diff --git a/cocos/scene-graph/prefab/utils.ts b/cocos/scene-graph/prefab/utils.ts index c6d7481b842..1bc009a92b7 100644 --- a/cocos/scene-graph/prefab/utils.ts +++ b/cocos/scene-graph/prefab/utils.ts @@ -40,8 +40,6 @@ import { ValueType } from '../../core/value-types'; export * from './prefab-info'; export function createNodeWithPrefab (node: Node): void { - // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. - // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 const prefabInfo = node?.prefab; if (!prefabInfo) { return; @@ -96,8 +94,6 @@ export function createNodeWithPrefab (node: Node): void { node[editorExtrasTag] = editorExtras; } - // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. - // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 if (node.prefab) { // just keep the instance node.prefab.instance = prefabInfo.instance; @@ -116,16 +112,12 @@ export function generateTargetMap (node: Node, targetMap: TargetMap, isRoot: boo let curTargetMap = targetMap; - // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. - // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 const prefabInstance = node.prefab?.instance; if (!isRoot && prefabInstance) { targetMap[prefabInstance.fileId] = {}; curTargetMap = targetMap[prefabInstance.fileId] as TargetMap; } - // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. - // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 const prefabInfo = node.prefab; if (prefabInfo) { curTargetMap[prefabInfo.fileId] = node; @@ -326,8 +318,6 @@ export function applyPropertyOverrides (node: Node, propertyOverrides: PropertyO } export function applyTargetOverrides (node: Node): void { - // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. - // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 const targetOverrides = node.prefab?.targetOverrides as TargetOverrideInfo[]; if (targetOverrides) { for (let i = 0; i < targetOverrides.length; i++) { @@ -391,8 +381,6 @@ export function applyTargetOverrides (node: Node): void { } export function expandPrefabInstanceNode (node: Node, recursively = false): void { - // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. - // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 const prefabInstance = node?.prefab?.instance as PrefabInstance; if (prefabInstance && !prefabInstance.expanded) { createNodeWithPrefab(node); @@ -423,8 +411,6 @@ export function expandPrefabInstanceNode (node: Node, recursively = false): void } export function expandNestedPrefabInstanceNode (node: Node): void { - // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion. - // Tracking issue: https://github.com/cocos/cocos-engine/issues/14613 const prefabInfo = node.prefab; if (prefabInfo && prefabInfo.nestedPrefabInstanceRoots) { From 57523ab456b843b4fa2695bac0a266cf9f951989 Mon Sep 17 00:00:00 2001 From: DogeFu <609075410@qq.com> Date: Wed, 9 Aug 2023 14:36:02 +0800 Subject: [PATCH 7/7] add prefab getter in node.jsb.ts --- cocos/scene-graph/node.jsb.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cocos/scene-graph/node.jsb.ts b/cocos/scene-graph/node.jsb.ts index 22b9a73c5f4..ed2e4274521 100644 --- a/cocos/scene-graph/node.jsb.ts +++ b/cocos/scene-graph/node.jsb.ts @@ -1016,6 +1016,14 @@ Object.defineProperty(nodeProto, '_siblingIndex', { }, }); +Object.defineProperty(nodeProto, 'prefab', { + configurable: true, + enumerable: true, + get() { + return this._prefab; + }, +}); + // External classes need to access it through getter/setter Object.defineProperty(nodeProto, 'siblingIndex', { configurable: true,