mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-05-22 17:06:53 +08:00
GameComponent添加批量绑定Button触摸事件功能
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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<Button>(Button);
|
||||
buttons.forEach((b: Button) => {
|
||||
var node = b.node;
|
||||
var self: any = this;
|
||||
var func = self[node.name];
|
||||
if (func)
|
||||
node.on(Node.EventType.TOUCH_END, func, this);
|
||||
else
|
||||
console.error(`名为【${node.name}】的按钮事件方法不存在`);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user