117 lines
3.1 KiB
TypeScript
117 lines
3.1 KiB
TypeScript
// Learn TypeScript:
|
|
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
|
|
// Learn Attribute:
|
|
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
|
|
// Learn life-cycle callbacks:
|
|
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
|
|
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
|
|
@ccclass
|
|
export default class setUi extends cc.Component {
|
|
static _instance: any;
|
|
time: number = 0;
|
|
|
|
@property(cc.Node)
|
|
music: cc.Node = null;
|
|
|
|
@property(cc.Node)
|
|
effect: cc.Node = null;
|
|
|
|
@property(cc.Node)
|
|
vibrate: cc.Node = null;
|
|
|
|
|
|
// mapInfo: number[][] = [];
|
|
|
|
musicState: boolean = true;
|
|
effectState: boolean = true;
|
|
vibrateState: boolean = true;
|
|
|
|
onLoad() {
|
|
|
|
this.musicState = cc.fx.GameConfig.GM_INFO.musicOpen;
|
|
this.effectState = cc.fx.GameConfig.GM_INFO.effectOpen;
|
|
this.vibrateState = cc.fx.GameConfig.GM_INFO.vibrateOpen;
|
|
console.log("音乐状态", this.musicState);
|
|
console.log("音效状态", this.effectState);
|
|
console.log("震动状态", this.vibrateState);
|
|
this.syncToggleState();
|
|
}
|
|
|
|
start() {
|
|
}
|
|
|
|
init(time) {
|
|
|
|
}
|
|
|
|
clickMusic() {
|
|
if (this.musicState) {
|
|
this.musicState = false;
|
|
cc.fx.GameConfig.GM_INFO.musicOpen = this.musicState;
|
|
|
|
this.setMusicConfig();
|
|
cc.fx.AudioManager._instance.stopMusic();
|
|
}
|
|
else {
|
|
this.musicState = true;
|
|
cc.fx.GameConfig.GM_INFO.musicOpen = this.musicState;
|
|
this.setMusicConfig();
|
|
cc.fx.AudioManager._instance.playMusicGame();
|
|
}
|
|
}
|
|
|
|
setMusicConfig() {
|
|
let audioInfo = {
|
|
"musicOpen": cc.fx.GameConfig.GM_INFO.musicOpen, //音乐
|
|
"effectOpen": cc.fx.GameConfig.GM_INFO.effectOpen, //音效
|
|
"vibrateOpen": cc.fx.GameConfig.GM_INFO.vibrateOpen, //震动
|
|
}
|
|
cc.fx.StorageMessage.setStorage("music", audioInfo);
|
|
}
|
|
|
|
clickEffect() {
|
|
if (this.effectState) {
|
|
this.effectState = false;
|
|
cc.fx.GameConfig.GM_INFO.effectOpen = this.effectState;
|
|
this.setMusicConfig();
|
|
}
|
|
else {
|
|
this.effectState = true;
|
|
cc.fx.GameConfig.GM_INFO.effectOpen = this.effectState;
|
|
this.setMusicConfig();
|
|
|
|
}
|
|
}
|
|
|
|
clickVibrate() {
|
|
if (this.vibrateState) {
|
|
this.vibrateState = false;
|
|
cc.fx.GameConfig.GM_INFO.vibrateOpen = this.vibrateState;
|
|
this.setMusicConfig();
|
|
|
|
}
|
|
else {
|
|
this.vibrateState = true;
|
|
cc.fx.GameConfig.GM_INFO.vibrateOpen = this.vibrateState;
|
|
this.setMusicConfig();
|
|
|
|
}
|
|
}
|
|
syncToggleState() {
|
|
this.music.getComponent(cc.Toggle).isChecked = !this.musicState;
|
|
this.effect.getComponent(cc.Toggle).isChecked = !this.effectState;
|
|
this.vibrate.getComponent(cc.Toggle).isChecked = !this.vibrateState;
|
|
}
|
|
|
|
//关闭ui
|
|
closeUi() {
|
|
this.node.active = false;
|
|
}
|
|
|
|
// update (dt) {}
|
|
}
|