From a503fb849c3104d1e7de4068124c7ce3760f03bc Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 17 Dec 2024 13:43:02 +0800 Subject: [PATCH] Fix cclegacy in node.jsb.ts and fix _onPostActivated. --- cocos/scene-graph/node.jsb.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/cocos/scene-graph/node.jsb.ts b/cocos/scene-graph/node.jsb.ts index a494d3cb9ab..07e6ba15720 100644 --- a/cocos/scene-graph/node.jsb.ts +++ b/cocos/scene-graph/node.jsb.ts @@ -21,7 +21,7 @@ */ import { EDITOR, EDITOR_NOT_IN_PREVIEW } from 'internal:constants'; -import { legacyCC } from '../core/global-exports'; +import { cclegacy } from '../core/global-exports'; import { errorID, getError } from '../core/platform/debug'; import { Component } from './component'; import { NodeEventType } from './node-event'; @@ -43,10 +43,11 @@ import { DispatcherEventType, NodeEventProcessor } from './node-event-processor' const reserveContentsForAllSyncablePrefabTag = Symbol('ReserveContentsForAllSyncablePrefab'); declare const jsb: any; +declare const EditorExtends: any; export const Node: typeof JsbNode = jsb.Node; export type Node = JsbNode; -legacyCC.Node = Node; +cclegacy.Node = Node; const NodeCls: any = Node; @@ -82,6 +83,7 @@ const TRANSFORMBIT_TRS = TransformBit.TRS; const nodeProto: any = jsb.Node.prototype; export const TRANSFORM_ON = 1 << 0; +const ACTIVE_ON = 1 << 1; const Destroying = CCObject.Flags.Destroying; // TODO: `_setTempFloatArray` is only implemented on Native platforms. @dumganhar @@ -163,7 +165,7 @@ nodeProto.addComponent = function (typeOrClassName) { if (typeof typeOrClassName === 'string') { constructor = getClassByName(typeOrClassName); if (!constructor) { - if (legacyCC._RF.peek()) { + if (cclegacy._RF.peek()) { errorID(3808, typeOrClassName); } throw TypeError(getError(3807, typeOrClassName)); @@ -222,7 +224,7 @@ nodeProto.addComponent = function (typeOrClassName) { } this.emit(NodeEventType.COMPONENT_ADDED, component); if (this._activeInHierarchy) { - legacyCC.director._nodeActivator.activateComp(component); + cclegacy.director._nodeActivator.activateComp(component); } if (EDITOR_NOT_IN_PREVIEW) { component.resetInEditor?.(); @@ -420,7 +422,7 @@ nodeProto._onEditorAttached = function (attached: boolean) { }; nodeProto._onRemovePersistRootNode = function () { - legacyCC.game.removePersistRootNode(this); + cclegacy.game.removePersistRootNode(this); }; nodeProto._onDestroyComponents = function () { @@ -497,10 +499,14 @@ nodeProto._onSiblingOrderChanged = function () { }; nodeProto._onActivateNode = function (shouldActiveNow) { - legacyCC.director._nodeActivator.activateNode(this, shouldActiveNow); + cclegacy.director._nodeActivator.activateNode(this, shouldActiveNow); }; nodeProto._onPostActivated = function (active: boolean) { + if (this._eventMask & ACTIVE_ON) { + this.emit(NodeEventType.ACTIVE_CHANGED, this, active); + } + const eventProcessor = this._eventProcessor; if (eventProcessor.isEnabled === active) { NodeEventProcessor.callbacksInvoker.emit(DispatcherEventType.MARK_LIST_DIRTY); @@ -605,7 +611,7 @@ NodeCls._findChildComponents = function (children, constructor, components) { // @ts-ignore NodeCls.isNode = function (obj: unknown): obj is jsb.Node { // @ts-ignore - return obj instanceof jsb.Node && (obj.constructor === jsb.Node || !(obj instanceof legacyCC.Scene)); + return obj instanceof jsb.Node && (obj.constructor === jsb.Node || !(obj instanceof cclegacy.Scene)); }; let _tempQuat = new Quat(); @@ -1266,7 +1272,7 @@ nodeProto[serializeTag] = function (serializationOutput: SerializationOutput, co }; nodeProto._onActiveNode = function (shouldActiveNow: boolean) { - legacyCC.director._nodeActivator.activateNode(this, shouldActiveNow); + cclegacy.director._nodeActivator.activateNode(this, shouldActiveNow); }; nodeProto._onBatchCreated = function (dontSyncChildPrefab: boolean) { @@ -1330,7 +1336,7 @@ nodeProto._onLocalPositionRotationScaleUpdated = function (px, py, pz, rx, ry, r nodeProto._instantiate = function (cloned: Node, isSyncedNode: boolean) { if (!cloned) { - cloned = legacyCC.instantiate._clone(this, this); + cloned = cclegacy.instantiate._clone(this, this); } // TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion.