Files
oops-plugin-framework/assets/libs/gui/button/ButtonEffect.ts
donggang 3040668482 1、添加通用按钮,支持短按触发、长按触发、按钮点击触发音效、防连点
2、音乐支持直接通过音乐资源对象播放音效、添加释放音效资源方法
2024-05-20 19:24:09 +08:00

59 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* @Author: dgflash
* @Date: 2023-01-30 14:00:41
* @LastEditors: dgflash
* @LastEditTime: 2023-02-09 10:54:28
*/
import { Animation, AnimationClip, EventTouch, Sprite, _decorator } from "cc";
import { oops } from "../../../core/Oops";
import ButtonSimple from "./ButtonSimple";
const { ccclass, property, menu } = _decorator;
/** 准备废弃请使用UIButton代替 */
@ccclass("ButtonEffect")
@menu('ui/button/ButtonEffect')
export default class ButtonEffect extends ButtonSimple {
@property({
tooltip: "是否开启"
})
disabledEffect: boolean = false;
private anim!: Animation;
/** 按钮禁用效果 */
get grayscale(): boolean {
return this.node.getComponent(Sprite)!.grayscale;
}
set grayscale(value: boolean) {
if (this.node.getComponent(Sprite)) {
this.node.getComponent(Sprite)!.grayscale = value;
}
}
onLoad() {
this.anim = this.node.addComponent(Animation);
var ac_start: AnimationClip = oops.res.get("common/anim/button_scale_start", AnimationClip)!;
var ac_end: AnimationClip = oops.res.get("common/anim/button_scale_end", AnimationClip)!;
this.anim.defaultClip = ac_start;
this.anim.createState(ac_start, ac_start?.name);
this.anim.createState(ac_end, ac_end?.name);
super.onLoad();
}
protected onTouchtStart(event: EventTouch) {
if (!this.disabledEffect) {
this.anim.play("button_scale_start");
}
}
protected onTouchEnd(event: EventTouch) {
if (!this.disabledEffect) {
this.anim.play("button_scale_end");
}
super.onTouchEnd(event);
}
}