From cae7d1a78efa9c85214e26015aa76a273c5a8b92 Mon Sep 17 00:00:00 2001 From: dgflash Date: Thu, 20 Mar 2025 16:18:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DUIButton=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=BC=A9=E6=94=BE=E5=8A=A8=E7=94=BB=E6=A8=A1=E5=BC=8F=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E8=BF=9E=E7=BB=AD=E7=82=B9=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=BC=A9=E6=94=BE=E5=8A=A8=E7=94=BB=E4=B8=8D?= =?UTF-8?q?=E6=81=A2=E5=A4=8D=E5=88=B0=E5=8E=9F=E5=A7=8B=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E5=B0=BA=E5=AF=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/libs/gui/button/UIButton.ts | 49 +++++++++++++++++++----------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/assets/libs/gui/button/UIButton.ts b/assets/libs/gui/button/UIButton.ts index 197111a..cadf999 100644 --- a/assets/libs/gui/button/UIButton.ts +++ b/assets/libs/gui/button/UIButton.ts @@ -1,6 +1,5 @@ -import { AudioClip, Button, EventTouch, _decorator, game } from "cc"; +import { AudioClip, Button, EventHandler, EventTouch, _decorator, game } from "cc"; import { oops } from "../../../core/Oops"; -import { resLoader } from "../../../core/common/loader/ResLoader"; const { ccclass, property, menu } = _decorator; @@ -36,26 +35,42 @@ export default class UIButton extends Button { /** 触摸结束 */ protected _onTouchEnded(event: EventTouch) { - // 是否只触发一次 - if (this.once) { - if (this._touchCount > 0) { - event.propagationStopped = true; - return; + if (!this._interactable || !this.enabledInHierarchy) { + return; + } + + //@ts-ignore + if (this._pressed) { + // 是否只触发一次 + if (this.once) { + if (this._touchCount > 0) { + event.propagationStopped = true; + return; + } + this._touchCount++; + } + + // 防连点500毫秒出发一次事件 + if (this._touchEndTime && game.totalTime - this._touchEndTime < this.interval) { + event.propagationStopped = true; + } + else { + this._touchEndTime = game.totalTime; + EventHandler.emitEvents(this.clickEvents, event); + this.node.emit(Button.EventType.CLICK, this); + + // 短按触摸音效 + this.playEffect(); } - this._touchCount++; } - // 防连点500毫秒出发一次事件 - if (this._touchEndTime && game.totalTime - this._touchEndTime < this.interval) { + //@ts-ignore + this._pressed = false; + this._updateState(); + + if (event) { event.propagationStopped = true; } - else { - this._touchEndTime = game.totalTime; - super._onTouchEnded(event); - - // 短按触摸音效 - this.playEffect(); - } } /** 短按触摸音效 */