From 5c79c3a16c804e585233819d51ca8dc63f58bd47 Mon Sep 17 00:00:00 2001 From: xu_yanfeng Date: Wed, 12 Feb 2025 09:50:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dv2=E7=89=88=E6=9C=AC=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=BC=82=E5=B8=B8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scripts/inject/code-hint.ts | 49 +++++++++++++++++++++++++-------- src/scripts/inject/inspector.ts | 5 ++-- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/scripts/inject/code-hint.ts b/src/scripts/inject/code-hint.ts index fe9ba33..af34c0d 100644 --- a/src/scripts/inject/code-hint.ts +++ b/src/scripts/inject/code-hint.ts @@ -46,18 +46,45 @@ function getButton(node: any, fillFn: boolean): FunctionInfo[] { return ret; } -export function getCallbacks(node: any, code: ShowCode, fillFn: boolean = false): FunctionInfo[] { +export function getCallbacks(node: any, code: ShowCode, fillFn: boolean, v2: boolean): FunctionInfo[] { if (node instanceof cc.Scene) { return []; } if (code === ShowCode.ButtonClickEvents) { return getButton(node, fillFn); } else { - return getTouch(node, code, fillFn); + if (v2) { + return getTouchV2(node, code, fillFn); + } else { + return getTouchV3(node, code, fillFn); + } } } - -function getTouch(node: any, code: ShowCode, fillFn: boolean = false): FunctionInfo[] { +function getTouchV2(node: any, code: ShowCode, fillFn: boolean): FunctionInfo[] { + const key = getKey(code); + if (!key) { + return []; + } + if (!node._bubblingListeners) { + return []; + } + if (!node._bubblingListeners._callbackTable) { + return []; + } + const tables = node._bubblingListeners._callbackTable[key]; + if (!tables) { + return []; + } + const infos: Array = tables.callbackInfos; + if (!infos || infos.length === 0) { + return []; + } + return infos.map((fun) => { + // @ts-ignore + return getFn(fun.callback, fillFn); + }); +} +function getTouchV3(node: any, code: ShowCode, fillFn: boolean): FunctionInfo[] { const key = getKey(code); if (!key) { return []; @@ -97,11 +124,11 @@ function getFn(item: Function, fillFn: boolean): FunctionInfo { } export const ANONYMOUS = "anonymous"; -export function calcCodeHint(node: any, data: TreeData) { - data.codeTouchStart = getCallbacks(node, ShowCode.TouchStart); - data.codeTouchMove = getCallbacks(node, ShowCode.TouchMove); - data.codeTouchEnd = getCallbacks(node, ShowCode.TouchEnd); - data.codeTouchCancel = getCallbacks(node, ShowCode.TouchCancel); - data.codeButtonClick = getCallbacks(node, ShowCode.ButtonClick); - data.codeButtonEvents = getCallbacks(node, ShowCode.ButtonClickEvents); +export function calcCodeHint(node: any, data: TreeData, v2: boolean) { + data.codeTouchStart = getCallbacks(node, ShowCode.TouchStart, false, v2); + data.codeTouchMove = getCallbacks(node, ShowCode.TouchMove, false, v2); + data.codeTouchEnd = getCallbacks(node, ShowCode.TouchEnd, false, v2); + data.codeTouchCancel = getCallbacks(node, ShowCode.TouchCancel, false, v2); + data.codeButtonClick = getCallbacks(node, ShowCode.ButtonClick, false, v2); + data.codeButtonEvents = getCallbacks(node, ShowCode.ButtonClickEvents, false, v2); } diff --git a/src/scripts/inject/inspector.ts b/src/scripts/inject/inspector.ts index 44257d2..68885c2 100644 --- a/src/scripts/inject/inspector.ts +++ b/src/scripts/inject/inspector.ts @@ -112,7 +112,7 @@ export class Inspector extends InjectEvent { if (!node || !node.isValid) { return; } - const funArray = getCallbacks(node, data.code, true); + const funArray = getCallbacks(node, data.code, true, this.isCreatorV2()); if (funArray && funArray.length && data.index < funArray.length) { const item = funArray[data.index]; this.target = item.fn; @@ -337,7 +337,8 @@ export class Inspector extends InjectEvent { data.text = node.name; data.icon = this.calcIcon(node); data.color = this.calcColor(node); - calcCodeHint(node, data); + const v2 = this.isCreatorV2(); + calcCodeHint(node, data, v2); // @ts-ignore if (node instanceof cc.Scene) { // 场景不允许获取active,引擎会报错