From 4edb3b0d6cd6e0ee229efc732e6f4abdf60240d6 Mon Sep 17 00:00:00 2001 From: donggang <> Date: Tue, 12 Mar 2024 09:37:29 +0800 Subject: [PATCH] =?UTF-8?q?GameComponent=E6=B7=BB=E5=8A=A0=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E7=BB=91=E5=AE=9AButton=E8=A7=A6=E6=91=B8=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/common/timer/TimerManager.ts | 2 +- assets/module/common/GameComponent.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/assets/core/common/timer/TimerManager.ts b/assets/core/common/timer/TimerManager.ts index 840ab0b..9d19aaa 100644 --- a/assets/core/common/timer/TimerManager.ts +++ b/assets/core/common/timer/TimerManager.ts @@ -74,7 +74,7 @@ export class TimerManager extends Component { } } */ - register(object: any, field: string, onSecond: Function, onComplete: Function): any { + register(object: any, field: string, onSecond: Function, onComplete: Function): string { var timer = new Timer(); timer.step = 1; diff --git a/assets/module/common/GameComponent.ts b/assets/module/common/GameComponent.ts index 1cd8e43..19598ef 100644 --- a/assets/module/common/GameComponent.ts +++ b/assets/module/common/GameComponent.ts @@ -4,7 +4,7 @@ * @LastEditors: dgflash * @LastEditTime: 2022-12-13 11:36:00 */ -import { Asset, Component, EventKeyboard, EventTouch, Input, Node, __private, _decorator, input } from "cc"; +import { Asset, Button, Component, EventKeyboard, EventTouch, Input, Node, __private, _decorator, input } from "cc"; import { oops } from "../../core/Oops"; import { EventDispatcher } from "../../core/common/event/EventDispatcher"; import { EventMessage, ListenerFunc } from "../../core/common/event/EventMessage"; @@ -233,6 +233,7 @@ export class GameComponent extends Component { this.setButtonList(args); } protected setButtonList(args: string[]) { + // 自定义按钮批量绑定触摸事件 this.node.on(Node.EventType.TOUCH_END, (event: EventTouch) => { var self: any = this; var func = self[event.target.name]; @@ -241,6 +242,18 @@ export class GameComponent extends Component { else console.error(`名为【${event.target.name}】的按钮事件方法不存在`); }, this); + + // Cocos Creator Button组件批量绑定触摸事件 + var buttons = this.node.getComponentsInChildren