mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-20 00:48:43 +00:00
检索node的touch、click回调事件
This commit is contained in:
parent
243d786666
commit
5fcbdd626b
@ -11,6 +11,7 @@ const manifest: CocosPluginManifest = {
|
|||||||
name: pkgName,
|
name: pkgName,
|
||||||
version: "2.1.7",
|
version: "2.1.7",
|
||||||
description: "Debug games made with CocosCreator and display node trees and node properties",
|
description: "Debug games made with CocosCreator and display node trees and node properties",
|
||||||
|
store: "https://store.cocos.com/app/detail/2002",
|
||||||
author: "xu_yanfeng",
|
author: "xu_yanfeng",
|
||||||
main: "./src/main.ts",
|
main: "./src/main.ts",
|
||||||
panels: [
|
panels: [
|
||||||
@ -42,6 +43,7 @@ const manifest: CocosPluginManifest = {
|
|||||||
// googleAnalytics: "G-0S2X4Z1FE7",
|
// googleAnalytics: "G-0S2X4Z1FE7",
|
||||||
},
|
},
|
||||||
chrome: {
|
chrome: {
|
||||||
|
url: "https://chromewebstore.google.com/detail/cc-inspector/hejbkamkfnkifppoaljcidepkhgaahcj?authuser=0&hl=en",
|
||||||
version: 3,
|
version: 3,
|
||||||
pem: "./crx-key.pem",
|
pem: "./crx-key.pem",
|
||||||
view_devtools: "src/views/devtools/index.ts",
|
view_devtools: "src/views/devtools/index.ts",
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { ShowCode } from "../scripts/inject/types";
|
||||||
import { Chunk } from "../scripts/terminal";
|
import { Chunk } from "../scripts/terminal";
|
||||||
import { FrameDetails, Info, NodeInfoData, TreeData } from "../views/devtools/data";
|
import { FrameDetails, Info, NodeInfoData, TreeData } from "../views/devtools/data";
|
||||||
|
|
||||||
@ -72,6 +73,7 @@ export interface ResponseUseFrameData {
|
|||||||
export type RequestSetPropertyData = Info;
|
export type RequestSetPropertyData = Info;
|
||||||
export type ResponseSetPropertyData = Info;
|
export type ResponseSetPropertyData = Info;
|
||||||
export type RequestLogData = string[];
|
export type RequestLogData = string[];
|
||||||
|
export type RequestOpenNodeTouchFuntionData = { uuid: string; code: ShowCode };
|
||||||
export type ResponseErrorData = string;
|
export type ResponseErrorData = string;
|
||||||
export enum Msg {
|
export enum Msg {
|
||||||
None = "None",
|
None = "None",
|
||||||
@ -135,6 +137,11 @@ export enum Msg {
|
|||||||
|
|
||||||
RequestDynamicAtlasView = "request-dynamic-atlas-view",
|
RequestDynamicAtlasView = "request-dynamic-atlas-view",
|
||||||
ResponseDynamicAtlasView = "response-dynamic-atlas-view",
|
ResponseDynamicAtlasView = "response-dynamic-atlas-view",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求在source面板打开节点的touch函数
|
||||||
|
*/
|
||||||
|
RequestOpenNodeTouchFuntion = "request-open-node-touch-funtion",
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PluginEvent {
|
export class PluginEvent {
|
||||||
|
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();
|
const inspector = new Inspector();
|
||||||
inspector.init();
|
inspector.init();
|
||||||
window["CCInspector"] = inspector;
|
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
|
// eval 注入脚本的代码,变量尽量使用var,后来发现在import之后,let会自动变为var
|
||||||
import { uniq } from "lodash";
|
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 { 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 { 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";
|
import { getEnumListConfig } from "./enumConfig";
|
||||||
@ -9,11 +9,16 @@ import { Hint } from "./hint";
|
|||||||
import { injectView } from "./inject-view";
|
import { injectView } from "./inject-view";
|
||||||
import { inspectTarget } from "./inspect-list";
|
import { inspectTarget } from "./inspect-list";
|
||||||
import { getValue, trySetValueWithConfig } from "./setValue";
|
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 { isHasProperty } from "./util";
|
||||||
|
import { calcCodeHint, getCallbacks } from "./code-hint";
|
||||||
|
|
||||||
declare const cc: any;
|
declare const cc: any;
|
||||||
export class Inspector extends InjectEvent {
|
export class Inspector extends InjectEvent {
|
||||||
|
/**
|
||||||
|
* 要inspect的函数
|
||||||
|
*/
|
||||||
|
public target: Function = null;
|
||||||
inspectorGameMemoryStorage: Record<string, any> = {};
|
inspectorGameMemoryStorage: Record<string, any> = {};
|
||||||
private hint: Hint = new Hint(this);
|
private hint: Hint = new Hint(this);
|
||||||
|
|
||||||
@ -101,6 +106,23 @@ export class Inspector extends InjectEvent {
|
|||||||
logFunction(value);
|
logFunction(value);
|
||||||
break;
|
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: {
|
case Msg.RequestLogCustom: {
|
||||||
const logFunction = console.log;
|
const logFunction = console.log;
|
||||||
logFunction(pluginEvent.data);
|
logFunction(pluginEvent.data);
|
||||||
@ -316,6 +338,7 @@ export class Inspector extends InjectEvent {
|
|||||||
data.text = node.name;
|
data.text = node.name;
|
||||||
data.icon = this.calcIcon(node);
|
data.icon = this.calcIcon(node);
|
||||||
data.color = this.calcColor(node);
|
data.color = this.calcColor(node);
|
||||||
|
calcCodeHint(node, data);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (node instanceof cc.Scene) {
|
if (node instanceof cc.Scene) {
|
||||||
// 场景不允许获取active,引擎会报错
|
// 场景不允许获取active,引擎会报错
|
||||||
|
@ -41,3 +41,10 @@ export interface BuildImageOptions {
|
|||||||
value: Object;
|
value: Object;
|
||||||
data: ImageData;
|
data: ImageData;
|
||||||
}
|
}
|
||||||
|
export enum ShowCode {
|
||||||
|
TouchStart = "touchstart",
|
||||||
|
TouchMove = "touchmove",
|
||||||
|
TouchEnd = "touchend",
|
||||||
|
TouchCancel = "touchcancel",
|
||||||
|
ButtonClick = "buttonclick",
|
||||||
|
}
|
||||||
|
@ -523,6 +523,14 @@ export class TreeData implements ITreeData {
|
|||||||
id: string = "";
|
id: string = "";
|
||||||
icon: string = "";
|
icon: string = "";
|
||||||
color: string = "";
|
color: string = "";
|
||||||
|
/**
|
||||||
|
* 回调的数量
|
||||||
|
*/
|
||||||
|
codeTouchStart: number = 0;
|
||||||
|
codeTouchMove: number = 0;
|
||||||
|
codeTouchEnd: number = 0;
|
||||||
|
codeTouchCancel: number = 0;
|
||||||
|
codeButtonClick: number = 0;
|
||||||
active: boolean = true;
|
active: boolean = true;
|
||||||
text: string = "";
|
text: string = "";
|
||||||
children: TreeData[] = [];
|
children: TreeData[] = [];
|
||||||
|
@ -22,9 +22,10 @@ import { HandExpandOptions } from "@xuyanfeng/cc-ui/types/cc-tree/const";
|
|||||||
import Mousetrap, { MousetrapInstance } from "mousetrap";
|
import Mousetrap, { MousetrapInstance } from "mousetrap";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import { defineComponent, nextTick, onMounted, onUnmounted, ref, toRaw, watch } from "vue";
|
import { defineComponent, nextTick, onMounted, onUnmounted, ref, toRaw, watch } from "vue";
|
||||||
import { Msg, PluginEvent, RequestTreeInfoData, RequestUseFrameData, ResponseSetPropertyData, ResponseSupportData } from "../../core/types";
|
import { Msg, PluginEvent, RequestOpenNodeTouchFuntionData, RequestTreeInfoData, RequestUseFrameData, ResponseSetPropertyData, ResponseSupportData } from "../../core/types";
|
||||||
import { ga } from "../../ga";
|
import { ga } from "../../ga";
|
||||||
import { GA_EventName } from "../../ga/type";
|
import { GA_EventName } from "../../ga/type";
|
||||||
|
import { ShowCode } from "../../scripts/inject/types";
|
||||||
import { bridge } from "./bridge";
|
import { bridge } from "./bridge";
|
||||||
import { Bus, BusMsg } from "./bus";
|
import { Bus, BusMsg } from "./bus";
|
||||||
import { RotateType } from "./const";
|
import { RotateType } from "./const";
|
||||||
@ -273,6 +274,57 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
onMenu(event: MouseEvent, data: TreeData) {
|
onMenu(event: MouseEvent, data: TreeData) {
|
||||||
const menus: IUiMenuItem[] = [];
|
const menus: IUiMenuItem[] = [];
|
||||||
|
if (data) {
|
||||||
|
function hintCode(type: ShowCode) {
|
||||||
|
bridge.send(Msg.RequestOpenNodeTouchFuntion, { uuid: data.id, code: type } as RequestOpenNodeTouchFuntionData);
|
||||||
|
chrome.devtools.inspectedWindow.eval(`DoInspect()`);
|
||||||
|
}
|
||||||
|
menus.push({
|
||||||
|
name: `code button-click [${data.codeButtonClick}]`,
|
||||||
|
visible: !!data.codeButtonClick,
|
||||||
|
callback: (item) => {
|
||||||
|
ga.fireEventWithParam(GA_EventName.MouseMenu, ShowCode.ButtonClick);
|
||||||
|
hintCode(ShowCode.ButtonClick);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
menus.push({
|
||||||
|
name: `code touch-start [${data.codeTouchStart}]`,
|
||||||
|
visible: !!data.codeTouchStart,
|
||||||
|
callback: (item) => {
|
||||||
|
ga.fireEventWithParam(GA_EventName.MouseMenu, ShowCode.TouchStart);
|
||||||
|
hintCode(ShowCode.TouchStart);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
menus.push({
|
||||||
|
name: `code touch-move [${data.codeTouchMove}]`,
|
||||||
|
visible: !!data.codeTouchMove,
|
||||||
|
callback: (item) => {
|
||||||
|
ga.fireEventWithParam(GA_EventName.MouseMenu, ShowCode.TouchMove);
|
||||||
|
hintCode(ShowCode.TouchMove);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
menus.push({
|
||||||
|
name: `code touch-end [${data.codeTouchEnd}]`,
|
||||||
|
visible: !!data.codeTouchEnd,
|
||||||
|
callback: (item) => {
|
||||||
|
ga.fireEventWithParam(GA_EventName.MouseMenu, ShowCode.TouchEnd);
|
||||||
|
hintCode(ShowCode.TouchEnd);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
menus.push({
|
||||||
|
name: `code touch-cancel [${data.codeTouchCancel}]`,
|
||||||
|
visible: !!data.codeTouchCancel,
|
||||||
|
callback: (item) => {
|
||||||
|
ga.fireEventWithParam(GA_EventName.MouseMenu, ShowCode.TouchCancel);
|
||||||
|
hintCode(ShowCode.TouchCancel);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (data.codeButtonClick || data.codeTouchStart || data.codeTouchMove || data.codeTouchEnd || data.codeTouchCancel) {
|
||||||
|
menus.push({ type: ccui.menu.MenuType.Separator });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
menus.push({
|
menus.push({
|
||||||
name: "update hierarchy",
|
name: "update hierarchy",
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user