[add] HoldButton 防止跟Button事件衝突
This commit is contained in:
@@ -113,7 +113,6 @@ export class Badminton extends cc.Component {
|
||||
//#region 初始化
|
||||
|
||||
protected onLoad(): void {
|
||||
// this.node.getChildByName("Test").getComponent(HoldButton).OnInvoke.AddListener(() => { this.OnChangeAvatar(666); });
|
||||
Badminton._instance = this;
|
||||
new LocalStorageData();
|
||||
this.config.Init();
|
||||
@@ -173,14 +172,13 @@ export class Badminton extends cc.Component {
|
||||
let picObj: cc.Node = item.node.getChildByName("Avatar").getChildByName("Pic");
|
||||
if (picObj != null) {
|
||||
picObj.getComponent(cc.Sprite).spriteFrame = this.config.GetAvatarPicById(this.TeamMemberList[idx].AvatarId);
|
||||
let EventHandler: cc.Component.EventHandler = new cc.Component.EventHandler();
|
||||
EventHandler.target = this.node;
|
||||
EventHandler.component = this.name.split("<")[1].split(">")[0];
|
||||
EventHandler.handler = "OnChangeAvatar";
|
||||
EventHandler.customEventData = idx.toString();
|
||||
picObj.getComponent(HoldButton).OnInvoke.push(EventHandler);
|
||||
// picObj.getComponent(HoldButton).OnInvoke.AddListener(this.OnChangeAvatar(idx));
|
||||
// picObj.getComponent(HoldButton).OnInvoke.AddListener(() => { this.OnChangeAvatar(idx); });
|
||||
// let EventHandler: cc.Component.EventHandler = new cc.Component.EventHandler();
|
||||
// EventHandler.target = this.node;
|
||||
// EventHandler.component = this.name.split("<")[1].split(">")[0];
|
||||
// EventHandler.handler = "OnChangeAvatar";
|
||||
// EventHandler.customEventData = idx.toString();
|
||||
// picObj.getComponent(HoldButton).OnInvoke.push(EventHandler);
|
||||
picObj.getComponent(HoldButton).OnInvoke.AddListener(() => { this.OnChangeAvatar(idx); });
|
||||
picObj.on("click", () => { item.isChecked = !item.isChecked; }, this);
|
||||
}
|
||||
this._m_toggleList.push(item);
|
||||
|
||||
@@ -30,6 +30,11 @@ export default class HoldButton extends cc.Component {
|
||||
|
||||
//#region private
|
||||
|
||||
/** 按钮的点击事件列表 */
|
||||
private _clickEvents: cc.Component.EventHandler[] = [];
|
||||
|
||||
private _isOnInvoke: boolean = false;
|
||||
|
||||
private _m_isMouseDown: boolean = false;
|
||||
|
||||
private _m_pressDeltaTime: number = 0;
|
||||
@@ -39,6 +44,8 @@ export default class HoldButton extends cc.Component {
|
||||
//#region Lifecycle
|
||||
|
||||
protected start(): void {
|
||||
this._clickEvents = this.getComponent(cc.Button).clickEvents.slice(0);
|
||||
this.getComponent(cc.Button).clickEvents.Clear();
|
||||
if (this.HoldLine != null) {
|
||||
this.HoldLine.active = false;
|
||||
}
|
||||
@@ -79,6 +86,7 @@ export default class HoldButton extends cc.Component {
|
||||
}
|
||||
|
||||
if (this._m_pressDeltaTime > this.MaxTime) {
|
||||
this._isOnInvoke = true;
|
||||
this._m_isMouseDown = false;
|
||||
if (this.IsHaveHoldLine) {
|
||||
this.HoldLine.active = false;
|
||||
@@ -116,6 +124,12 @@ export default class HoldButton extends cc.Component {
|
||||
if (this.IsHaveHoldLine) {
|
||||
this.HoldLine.active = false;
|
||||
}
|
||||
if (!this._isOnInvoke) {
|
||||
this._clickEvents.forEach((eventHandler: cc.Component.EventHandler) => {
|
||||
eventHandler.emit([this.node.getComponent(cc.Button)]);
|
||||
});
|
||||
}
|
||||
this._isOnInvoke = false;
|
||||
this._checkHoldAutoStart(0);
|
||||
}
|
||||
|
||||
@@ -125,6 +139,12 @@ export default class HoldButton extends cc.Component {
|
||||
if (this.IsHaveHoldLine) {
|
||||
this.HoldLine.active = false;
|
||||
}
|
||||
if (!this._isOnInvoke) {
|
||||
this._clickEvents.forEach((eventHandler: cc.Component.EventHandler) => {
|
||||
eventHandler.emit([this.node.getComponent(cc.Button)]);
|
||||
});
|
||||
}
|
||||
this._isOnInvoke = false;
|
||||
this._checkHoldAutoStart(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ declare interface Array<T> {
|
||||
*/
|
||||
ObjectSort(asc?: boolean[], key?: string[]): any[];
|
||||
/**
|
||||
* 設計給Array<cc.Component.EventHandler>使用
|
||||
* 設計給Array<cc.Component.EventHandler>forHoldButton使用
|
||||
* Add a non persistent listener to the UnityEvent.
|
||||
* @param call Callback function.
|
||||
*/
|
||||
|
||||
19
assets/Script/Test.ts
Normal file
19
assets/Script/Test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
// Learn TypeScript:
|
||||
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
|
||||
// Learn Attribute:
|
||||
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
|
||||
// Learn life-cycle callbacks:
|
||||
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
|
||||
|
||||
const { ccclass, property } = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
export default class Test extends cc.Component {
|
||||
|
||||
/**
|
||||
* name
|
||||
*/
|
||||
public Log(a, b): void {
|
||||
cc.log(b);
|
||||
}
|
||||
}
|
||||
9
assets/Script/Test.ts.meta
Normal file
9
assets/Script/Test.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.8",
|
||||
"uuid": "cf85b712-f2a5-4b43-982b-1522b88350fa",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
Reference in New Issue
Block a user