58e3cacf-3a62-439b-af8c-d2bf2d295f7a.js 2.73 KB
"use strict";
cc._RF.push(module, '58e3crPOmJDm6+M0r8tKV96', 'SoundEffectButton');
// script/common/components/SoundEffectButton.ts

"use strict";
// Learn TypeScript:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const GameBasicSettings_1 = require("../gameplay/settings/GameBasicSettings");
const { ccclass, property } = cc._decorator;
let SoundEffectButton = /** @class */ (() => {
    let SoundEffectButton = class SoundEffectButton extends cc.Component {
        constructor() {
            super(...arguments);
            this.clip = null;
            this.interactable = true;
            // update (dt) {}
        }
        // LIFE-CYCLE CALLBACKS:
        onLoad() {
        }
        onEnable() {
            this.node.on(cc.Node.EventType.TOUCH_END, this.onPlaySoundEffectCallback, this);
        }
        onDisable() {
            this.node.off(cc.Node.EventType.TOUCH_END, this.onPlaySoundEffectCallback, this);
        }
        onPlaySoundEffectCallback(event) {
            if (!this.clip) {
                console.log("current clip is null.");
            }
            else if (this.interactable) {
                if (GameBasicSettings_1.GameBasicSettings.soundVolume != 0)
                    cc.audioEngine.playEffect(this.clip, false);
            }
        }
        start() {
        }
    };
    __decorate([
        property({ type: cc.AudioClip })
    ], SoundEffectButton.prototype, "clip", void 0);
    SoundEffectButton = __decorate([
        ccclass
    ], SoundEffectButton);
    return SoundEffectButton;
})();
exports.default = SoundEffectButton;

cc._RF.pop();