From 119b570d27f16cc47353742bb49fbd9712116d63 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 17 Dec 2024 15:05:43 +0800 Subject: [PATCH] [v3.8.5] Fix NodeEventType.ACTIVE_CHANGED logic was not synchronized to native. (#18048) Unit Tests only run on web platform, I forgot to change node.jsb.ts. Previous PR: https://github.com/cocos/cocos-engine/pull/17141 --- cocos/scene-graph/node.jsb.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cocos/scene-graph/node.jsb.ts b/cocos/scene-graph/node.jsb.ts index 4b99c37f42b..c9b6f2ed261 100644 --- a/cocos/scene-graph/node.jsb.ts +++ b/cocos/scene-graph/node.jsb.ts @@ -81,6 +81,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 @@ -262,6 +263,9 @@ nodeProto.on = function (type, callback, target, useCapture: any = false) { this._registeredNodeEventTypeMask |= REGISTERED_EVENT_MASK_TRANSFORM_CHANGED; } break; + case NodeEventType.ACTIVE_CHANGED: + this._eventMask |= ACTIVE_ON; + break; case NodeEventType.PARENT_CHANGED: if (!(this._registeredNodeEventTypeMask & REGISTERED_EVENT_MASK_PARENT_CHANGED)) { this._registerOnParentChanged(); @@ -308,6 +312,9 @@ nodeProto.off = function (type: string, callback?, target?, useCapture = false) case NodeEventType.TRANSFORM_CHANGED: this._eventMask &= ~TRANSFORM_ON; break; + case NodeEventType.ACTIVE_CHANGED: + this._eventMask &= ~ACTIVE_ON; + break; default: break; } @@ -336,6 +343,10 @@ nodeProto.targetOff = function (target: string | unknown) { if ((this._eventMask & TRANSFORM_ON) && !this._eventProcessor.hasEventListener(NodeEventType.TRANSFORM_CHANGED)) { this._eventMask &= ~TRANSFORM_ON; } + + if ((this._eventMask & ACTIVE_ON) && !this._eventProcessor.hasEventListener(NodeEventType.ACTIVE_CHANGED)) { + this._eventMask &= ~ACTIVE_ON; + } }; nodeProto.pauseSystemEvents = function pauseSystemEvents(recursive: boolean): void { @@ -500,6 +511,10 @@ nodeProto._onActivateNode = function (shouldActiveNow) { }; nodeProto._onPostActivated = function (active: boolean) { + if (this._eventMask & ACTIVE_ON) { + this.emit(NodeEventType.ACTIVE_CHANGED, this, active); + } + this._eventProcessor.setEnabled(active); if (active) { // in case transform updated during deactivated period @@ -1263,6 +1278,12 @@ nodeProto._onActiveNode = function (shouldActiveNow: boolean) { }; nodeProto._onBatchCreated = function (dontSyncChildPrefab: boolean) { + if (this._eventMask & ACTIVE_ON) { + if (!this._activeInHierarchy) { + this.emit(NodeEventType.ACTIVE_CHANGED, this, false); + } + } + this.hasChangedFlags = TRANSFORMBIT_TRS; const children = this._children; const len = children.length;