MatchMaster/assets/gacha_bundle/script/playGacha.ts
2026-07-30 12:22:02 +08:00

85 lines
2.2 KiB
TypeScript

// Learn TypeScript:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
const { ccclass, property } = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property
text: string = 'hello';
@property(cc.AudioClip)
buttonAudio: cc.AudioClip = null;
@property(cc.AudioClip)
dropAudio: cc.AudioClip = null;
@property(cc.AudioClip)
openAudio: cc.AudioClip = null;
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start() {
this.node.on(cc.Node.EventType.TOUCH_START, this.touchStartCallback, this);
}
touchStartCallback() {
// this.playGachaEffect("button");
// setTimeout(() => {
// if (this.node) {
// if (this.node.parent) {
// this.node.parent.parent.parent.getComponent("GachaManager").playGacha2();
// }
// }
// }, 1000);
if (this.node) {
if (this.node.parent) {
this.node.parent.parent.parent.getComponent("GachaManager").playGacha2();
}
}
}
/** 播放抽猫流程音效,并沿用游戏现有的音效开关。 */
public playGachaEffect(type: string) {
if (cc.fx.GameConfig.GM_INFO
&& cc.fx.GameConfig.GM_INFO.effectOpen === false) {
return;
}
let clip: cc.AudioClip = null;
if (type === "button") {
clip = this.buttonAudio;
}
else if (type === "drop") {
clip = this.dropAudio;
}
else if (type === "open") {
clip = this.openAudio;
}
if (!clip) {
return;
}
const audioManager = cc.fx.AudioManager && cc.fx.AudioManager._instance;
if (audioManager && audioManager.play) {
audioManager.play(clip, false, null, false);
}
else {
cc.audioEngine.playEffect(clip, false);
}
}
// update (dt) {}
}