[add] HoldButton 防止跟Button事件衝突

This commit is contained in:
2022-05-02 22:27:29 +08:00
parent d012d3a6a1
commit 4a033f606c
6 changed files with 93 additions and 20 deletions

View File

@@ -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);
}