[fix] HoldButton 點擊事件衝突

This commit is contained in:
建喵 2022-05-08 13:29:13 +08:00
parent 6bc14bc92a
commit b644e0e0ab

View File

@ -36,6 +36,8 @@ export default class HoldButton extends cc.Component {
private _m_pressDeltaTime: number = 0; private _m_pressDeltaTime: number = 0;
private _scale: cc.Vec3 = null;
//#endregion //#endregion
//#region Lifecycle //#region Lifecycle
@ -44,6 +46,7 @@ export default class HoldButton extends cc.Component {
if (this.HoldLine != null) { if (this.HoldLine != null) {
this.HoldLine.active = false; this.HoldLine.active = false;
} }
this._scale = this._scale;
} }
protected update(dt: number): void { protected update(dt: number): void {
@ -58,13 +61,13 @@ export default class HoldButton extends cc.Component {
protected onEnable(): void { protected onEnable(): void {
this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchStart, this); this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchStart, this);
this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnd, this); this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchCancel, this);
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this); this.node.on(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this);
} }
protected onDisable(): void { protected onDisable(): void {
this.node.off(cc.Node.EventType.TOUCH_START, this._onTouchStart, this); this.node.off(cc.Node.EventType.TOUCH_START, this._onTouchStart, this);
this.node.off(cc.Node.EventType.TOUCH_END, this._onTouchEnd, this); this.node.off(cc.Node.EventType.TOUCH_END, this._onTouchCancel, this);
this.node.off(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this); this.node.off(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this);
} }
@ -100,6 +103,8 @@ export default class HoldButton extends cc.Component {
} }
}); });
} }
this.node.active = false;
this.node.active = true;
} }
} }
@ -117,17 +122,6 @@ export default class HoldButton extends cc.Component {
} }
} }
private _onTouchEnd(event: cc.Event.EventTouch): void {
this.node.resumeSystemEvents(true);
this._m_isMouseDown = false;
this._m_pressDeltaTime = 0;
if (this.IsHaveHoldLine) {
this.HoldLine.active = false;
}
this._isOnInvoke = false;
this._checkHoldAutoStart(0);
}
private _onTouchCancel(event: cc.Event.EventTouch): void { private _onTouchCancel(event: cc.Event.EventTouch): void {
this.node.resumeSystemEvents(true); this.node.resumeSystemEvents(true);
this._m_isMouseDown = false; this._m_isMouseDown = false;