future 1 jaar geleden
bovenliggende
commit
c3449ee179

+ 5 - 5
assets/scene/main.scene

@@ -105,7 +105,7 @@
     "_lpos": {
       "__type__": "cc.Vec3",
       "x": 540,
-      "y": 960.0000000000002,
+      "y": 960,
       "z": 0
     },
     "_lrot": {
@@ -192,7 +192,7 @@
     "_contentSize": {
       "__type__": "cc.Size",
       "width": 1080,
-      "height": 1920.0000000000002
+      "height": 1920
     },
     "_anchorPoint": {
       "__type__": "cc.Vec2",
@@ -290,7 +290,7 @@
     "_priority": 0,
     "_fov": 45,
     "_fovAxis": 0,
-    "_orthoHeight": 960.0000000000001,
+    "_orthoHeight": 960,
     "_near": 0,
     "_far": 1000,
     "_color": {
@@ -561,7 +561,7 @@
     "_contentSize": {
       "__type__": "cc.Size",
       "width": 1080,
-      "height": 1920.0000000000002
+      "height": 1920
     },
     "_anchorPoint": {
       "__type__": "cc.Vec2",
@@ -867,7 +867,7 @@
     "_contentSize": {
       "__type__": "cc.Size",
       "width": 1080,
-      "height": 1920.0000000000002
+      "height": 1920
     },
     "_anchorPoint": {
       "__type__": "cc.Vec2",

+ 22 - 1
assets/script/GameManager.ts

@@ -1,9 +1,30 @@
-import { _decorator, Component, Node } from 'cc';
+import { _decorator, Component, Node, sys } from 'cc';
+import { config } from './config';
+import { settingData } from './data';
 const { ccclass, property } = _decorator;
 
 @ccclass('GameManager')
 export class GameManager extends Component {
     public static openId:string = 'asd'
+
+
+    public static getSettingData():settingData {
+        let str = sys.localStorage.getItem(config.SETTING_DATA)
+        let data = new settingData
+        if(str==undefined||str==""||str==null){
+            data.isOpenYinYue = true
+            data.isOpenYinXiao = true
+            data.isOpenZhendong = true
+        } else {
+            data = JSON.parse(str)
+        }
+        return data;
+    }
+
+    public static saveSettingData(data:settingData) {
+        sys.localStorage.setItem(config.SETTING_DATA, JSON.stringify(data));
+
+    }
 }
 
 

+ 2 - 0
assets/script/config.ts

@@ -27,6 +27,8 @@ export class config  {
         }
     }
 
+    static SETTING_DATA:string = "SETTING_DATA"
+
     public static AD_TYPE = {
         UNKNOWN:""
     }

+ 6 - 0
assets/script/data.ts

@@ -17,6 +17,12 @@ export class model_content_item_data{
     public item_type:number = -1;
 }
 
+export class settingData{
+    public isOpenYinYue:boolean = true; //是否开启音乐
+    public isOpenYinXiao:boolean = true; //是否开启音效
+    public isOpenZhendong:boolean = true; //是否开启震动
+}
+
 export class level_data{
     public content:level_item_data[] = []
 }

+ 17 - 1
assets/script/manager/audioManager.ts

@@ -1,6 +1,7 @@
 import { _decorator, AudioClip, AudioSource, Component, Node, tween } from 'cc';
 import { ResourceUtil } from './ResourceUtil';
 import { config } from '../config';
+import { GameManager } from '../GameManager';
 const { ccclass, property } = _decorator;
 
 @ccclass('audioManager')
@@ -18,6 +19,8 @@ export class audioManager extends Component {
         this.init()
     }
     protected onLoad(): void {
+        let setting_data = GameManager.getSettingData()
+        if(setting_data.isOpenYinYue==false) { return }
         this.scheduleOnce(()=>{
             this.playMusic(config.AUDIO.home_bgm)
         },3)
@@ -62,12 +65,12 @@ export class audioManager extends Component {
         }
     }
     public playSound(path:string,soundVolume:number = null){
+        if(!GameManager.getSettingData().isOpenYinXiao) {return}
         if(path.length<=0){
             return
         }
         let loop:boolean = false
         let play = (node)=>{
-
             node.getComponent(AudioSource).play()
 
             // node.getComponent(AudioSource).playOneShot(node.getComponent(AudioSource).clip,soundVolume?soundVolume:this.soundVolume)
@@ -90,6 +93,19 @@ export class audioManager extends Component {
         }
         return this.node.addComponent(AudioSource)
     }
+
+    public playHomeBgm() {
+        if(this.getSound().clip==null){
+            this.playMusic(config.AUDIO.home_bgm)
+        } else {
+            this.getSound().loop = true;
+            this.getSound().play()
+        }
+    }
+
+    public pauseHomeBgm() {
+        this.getSound().stop()
+    }
 }
 
 

+ 21 - 3
assets/script/ui/setting/setting.ts

@@ -1,6 +1,8 @@
 import { _decorator, Component, Node, Toggle } from 'cc';
 import { uiManager } from '../../manager/uiManager';
 import { base_ui } from '../../fw/base_ui';
+import { audioManager } from '../../manager/audioManager';
+import { GameManager } from '../../GameManager';
 const { ccclass, property } = _decorator;
 
 @ccclass('setting')
@@ -19,9 +21,11 @@ export class setting extends base_ui {
         })
         this.onButtonListen(this.yinyue_btn_on, ()=>{
             this.updateYinyueStatus(false)
+            audioManager.Instance().pauseHomeBgm()
         })
         this.onButtonListen(this.yinyue_btn_off, ()=>{
             this.updateYinyueStatus(true)
+            audioManager.Instance().playHomeBgm()
         })
         this.onButtonListen(this.shengyin_btn_on, ()=>{
             this.updateShengyinStatus(false)
@@ -36,9 +40,14 @@ export class setting extends base_ui {
             this.updateZhendongStatus(true)
         })
 
-        this.updateYinyueStatus(true)
-        this.updateShengyinStatus(true)
-        this.updateZhendongStatus(true)
+        this.initData()
+    }
+
+    initData() {
+        let setting_data = GameManager.getSettingData()
+        this.updateYinyueStatus(setting_data.isOpenYinYue)
+        this.updateShengyinStatus(setting_data.isOpenYinXiao)
+        this.updateZhendongStatus(setting_data.isOpenZhendong)
     }
 
     updateYinyueStatus(open:boolean) {
@@ -49,6 +58,9 @@ export class setting extends base_ui {
             this.yinyue_btn_on.active = false
             this.yinyue_btn_off.active = true
         }
+        let setting_data = GameManager.getSettingData()
+        setting_data.isOpenYinYue = open
+        GameManager.saveSettingData(setting_data)
     }
 
     updateShengyinStatus(open:boolean) {
@@ -59,6 +71,9 @@ export class setting extends base_ui {
             this.shengyin_btn_on.active = false
             this.shengyin_btn_off.active = true
         }
+        let setting_data = GameManager.getSettingData()
+        setting_data.isOpenYinXiao = open
+        GameManager.saveSettingData(setting_data)
     }
 
     updateZhendongStatus(open:boolean) {
@@ -69,6 +84,9 @@ export class setting extends base_ui {
             this.zhendong_btn_on.active = false
             this.zhendong_btn_off.active = true
         }
+        let setting_data = GameManager.getSettingData()
+        setting_data.isOpenZhendong = open
+        GameManager.saveSettingData(setting_data)
     }
 }