mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-11-05 06:15:24 +00:00
检索node的touch、click回调事件
This commit is contained in:
46
src/scripts/inject/code-hint.ts
Normal file
46
src/scripts/inject/code-hint.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { TreeData } from "../../views/devtools/data";
|
||||
import { ShowCode } from "./types";
|
||||
declare const cc: any;
|
||||
|
||||
function getKey(code: ShowCode): string {
|
||||
const map = {};
|
||||
map[ShowCode.TouchStart] = cc.Node.EventType.TOUCH_START;
|
||||
map[ShowCode.TouchMove] = cc.Node.EventType.TOUCH_MOVE;
|
||||
map[ShowCode.TouchEnd] = cc.Node.EventType.TOUCH_END;
|
||||
map[ShowCode.TouchCancel] = cc.Node.EventType.TOUCH_CANCEL;
|
||||
map[ShowCode.ButtonClick] = cc.Button.EventType.CLICK;
|
||||
const key = map[code];
|
||||
return key || "";
|
||||
}
|
||||
|
||||
export function getCallbacks(node: any, code: ShowCode) {
|
||||
const key = getKey(code);
|
||||
if (!key) {
|
||||
return [];
|
||||
}
|
||||
if (!node._eventProcessor.bubblingTarget) {
|
||||
return [];
|
||||
}
|
||||
const tables = node._eventProcessor.bubblingTarget._callbackTable[key];
|
||||
if (!tables) {
|
||||
return [];
|
||||
}
|
||||
const funArray: Function[] = tables.callbackInfos;
|
||||
if (!funArray || funArray.length === 0) {
|
||||
return [];
|
||||
}
|
||||
if (funArray.length > 1) {
|
||||
console.warn(`多个事件回调函数${funArray.length}`);
|
||||
}
|
||||
return funArray.map((fun) => {
|
||||
// @ts-ignore
|
||||
return fun.callback;
|
||||
});
|
||||
}
|
||||
export function calcCodeHint(node: any, data: TreeData) {
|
||||
data.codeTouchStart = getCallbacks(node, ShowCode.TouchStart).length;
|
||||
data.codeTouchMove = getCallbacks(node, ShowCode.TouchMove).length;
|
||||
data.codeTouchEnd = getCallbacks(node, ShowCode.TouchEnd).length;
|
||||
data.codeTouchCancel = getCallbacks(node, ShowCode.TouchCancel).length;
|
||||
data.codeButtonClick = getCallbacks(node, ShowCode.ButtonClick).length;
|
||||
}
|
||||
@@ -2,3 +2,12 @@ import { Inspector } from "./inspector";
|
||||
const inspector = new Inspector();
|
||||
inspector.init();
|
||||
window["CCInspector"] = inspector;
|
||||
|
||||
window["DoInspect"] = function () {
|
||||
const t = inspector.target;
|
||||
if (typeof t === "function") {
|
||||
//@ts-ignore
|
||||
inspect(t);
|
||||
}
|
||||
inspector.target = null;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// eval 注入脚本的代码,变量尽量使用var,后来发现在import之后,let会自动变为var
|
||||
import { uniq } from "lodash";
|
||||
import { Msg, PluginEvent, RequestLogData, RequestNodeInfoData, RequestSetPropertyData, ResponseGameInfoData, ResponseNodeInfoData, ResponseSetPropertyData, ResponseSupportData, ResponseTreeInfoData } from "../../core/types";
|
||||
import { Msg, PluginEvent, RequestLogData, RequestNodeInfoData, RequestOpenNodeTouchFuntionData, RequestSetPropertyData, ResponseGameInfoData, ResponseNodeInfoData, ResponseSetPropertyData, ResponseSupportData, ResponseTreeInfoData } from "../../core/types";
|
||||
import { CompType, getNodeIcon } from "../../views/devtools/comp";
|
||||
import { ArrayData, BoolData, ColorData, DataType, EngineData, EnumData, Group, ImageData, Info, InvalidData, NodeInfoData, NumberData, ObjectCircleData, ObjectData, Property, StringData, TreeData, Vec2Data, Vec3Data, Vec4Data } from "../../views/devtools/data";
|
||||
import { getEnumListConfig } from "./enumConfig";
|
||||
@@ -9,11 +9,16 @@ import { Hint } from "./hint";
|
||||
import { injectView } from "./inject-view";
|
||||
import { inspectTarget } from "./inspect-list";
|
||||
import { getValue, trySetValueWithConfig } from "./setValue";
|
||||
import { BuildArrayOptions, BuildImageOptions, BuildObjectOptions, BuildVecOptions } from "./types";
|
||||
import { BuildArrayOptions, BuildImageOptions, BuildObjectOptions, BuildVecOptions, ShowCode } from "./types";
|
||||
import { isHasProperty } from "./util";
|
||||
import { calcCodeHint, getCallbacks } from "./code-hint";
|
||||
|
||||
declare const cc: any;
|
||||
export class Inspector extends InjectEvent {
|
||||
/**
|
||||
* 要inspect的函数
|
||||
*/
|
||||
public target: Function = null;
|
||||
inspectorGameMemoryStorage: Record<string, any> = {};
|
||||
private hint: Hint = new Hint(this);
|
||||
|
||||
@@ -101,6 +106,23 @@ export class Inspector extends InjectEvent {
|
||||
logFunction(value);
|
||||
break;
|
||||
}
|
||||
case Msg.RequestOpenNodeTouchFuntion: {
|
||||
const data: RequestOpenNodeTouchFuntionData = pluginEvent.data;
|
||||
const node = this.inspectorGameMemoryStorage[data.uuid];
|
||||
if (!node || !node.isValid) {
|
||||
return;
|
||||
}
|
||||
const funArray = getCallbacks(node, data.code);
|
||||
if (funArray && funArray.length) {
|
||||
// @ts-ignore
|
||||
const fn = funArray[0];
|
||||
this.target = fn;
|
||||
if (funArray.length !== 1) {
|
||||
debugger;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Msg.RequestLogCustom: {
|
||||
const logFunction = console.log;
|
||||
logFunction(pluginEvent.data);
|
||||
@@ -316,6 +338,7 @@ export class Inspector extends InjectEvent {
|
||||
data.text = node.name;
|
||||
data.icon = this.calcIcon(node);
|
||||
data.color = this.calcColor(node);
|
||||
calcCodeHint(node, data);
|
||||
// @ts-ignore
|
||||
if (node instanceof cc.Scene) {
|
||||
// 场景不允许获取active,引擎会报错
|
||||
|
||||
@@ -41,3 +41,10 @@ export interface BuildImageOptions {
|
||||
value: Object;
|
||||
data: ImageData;
|
||||
}
|
||||
export enum ShowCode {
|
||||
TouchStart = "touchstart",
|
||||
TouchMove = "touchmove",
|
||||
TouchEnd = "touchend",
|
||||
TouchCancel = "touchcancel",
|
||||
ButtonClick = "buttonclick",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user