Browse Source

增加静音功能

大爷 1 year ago
parent
commit
4ea3f51b2d

+ 14 - 0
FGUIProject/assets/HUD/Button4.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<component size="300,100" extention="Button">
+  <controller name="button" pages="0,up,1,down,2,over,3,selectedOver" selected="0"/>
+  <displayList>
+    <text id="n1_icx3" name="title" xy="3,0" size="205,100" fontSize="54" align="center" vAlign="middle" autoSize="none" singleLine="true" text="Mute">
+      <relation target="" sidePair="width-width,height-height"/>
+    </text>
+    <image id="n3_icx3" name="n3" src="icx38l" fileName="I_btn_zdyy.png" xy="210,4" size="94,100" aspect="true">
+      <relation target="" sidePair="width-width,height-height"/>
+    </image>
+    <image id="n2_icx3" name="checked" src="icx38m" fileName="I_icon_zdyy.png" xy="228,32"/>
+  </displayList>
+  <Button/>
+</component>

+ 4 - 1
FGUIProject/assets/HUD/HUD.xml

@@ -12,7 +12,10 @@
     <component id="n17_o3v3" name="btn_func2" src="o3v38i" fileName="Button3.xml" xy="1275,514" size="300,100" group="n14_o3v3"/>
     <component id="n18_o3v3" name="btn_func3" src="o3v38i" fileName="Button3.xml" xy="1275,664" size="300,100" group="n14_o3v3"/>
     <component id="n19_o3v3" name="btn_func4" src="o3v38i" fileName="Button3.xml" xy="1275,814" size="300,100" group="n14_o3v3"/>
-    <group id="n14_o3v3" name="n14" xy="1275,364" size="300,550"/>
+    <component id="n20_icx3" name="btn_mute" src="icx38n" fileName="Button4.xml" xy="1268,160" group="n14_o3v3">
+      <Button title="Mute"/>
+    </component>
+    <group id="n14_o3v3" name="n14" xy="1268,160" size="307,754"/>
   </displayList>
   <Button downEffect="dark" downEffectValue=".71"/>
 </component>

BIN
FGUIProject/assets/HUD/I_btn_zdyy.png


BIN
FGUIProject/assets/HUD/I_icon_zdyy.png


+ 3 - 0
FGUIProject/assets/HUD/package.xml

@@ -13,6 +13,9 @@
     <component id="o3v38i" name="Button3.xml" path="/"/>
     <image id="o3v38j" name="shcj_sxxlbtn01_sel.png" path="/"/>
     <image id="icx38k" name="shcj_btn_nor.png" path="/"/>
+    <image id="icx38l" name="I_btn_zdyy.png" path="/"/>
+    <image id="icx38m" name="I_icon_zdyy.png" path="/"/>
+    <component id="icx38n" name="Button4.xml" path="/"/>
   </resources>
   <publish name=""/>
 </packageDescription>

BIN
Unity/Assets/Res/FGUI/HUD_atlas0.png


BIN
Unity/Assets/Res/FGUI/HUD_fui.bytes


+ 2 - 0
Unity/Assets/Scripts/Codes/Hotfix/Client/EntryEvent2_InitClient.cs

@@ -5,6 +5,8 @@
     {
         protected override async ETTask Run(Scene scene, ET.EventType.EntryEvent2 args)
         {
+            Game.AddSingleton<GameSetting>();
+
             //加载战斗相关资源
             Game.AddSingleton<BattleResourceMgr>();
             Game.AddSingleton<BattleUnitFactory>();

+ 3 - 1
Unity/Assets/Scripts/Codes/HotfixView/Client/Sound/SoundManager.cs

@@ -41,7 +41,9 @@ public class SoundManager : Singleton<SoundManager>, ISingletonAwake
         UnityAudioSource.loop = true;
         UnityAudioSource.volume = 1f;
         UnityAudioSource.playOnAwake = false;
-        UnityAudioSource.mute = false;
+
+        var mute = GameSetting.Instance.GetBool(GameSetting.Sets.Mute_int);
+        UnityAudioSource.mute = mute;
     }
 
     public async ETTask PlayBgm(string name)

+ 14 - 1
Unity/Assets/Scripts/Codes/HotfixView/Client/UI/HUD/SceneChangeFinishEvent_CreateHUD.cs

@@ -63,10 +63,23 @@ namespace ET.Client
             {
                 var btn = view.GetChild($"btn_func{i}");
                 var index = i;
-                btn.onClick.Set(() => {
+                btn.onClick.Set(() =>
+                {
                     EventSystem.Instance.Publish<BattleFunc>(BattleFunc.Static.Clone(index));
                 });
             }
+
+            bool isMute = SoundManager.Instance.UnityAudioSource.mute;
+            var btnmute = view.GetChild("btn_mute");
+            var gou = (btnmute as GComponent).GetChild("checked");
+            gou.visible = isMute;
+            btnmute.onClick.Set(() =>
+            {
+                isMute = !isMute;
+                gou.visible = isMute;
+                SoundManager.Instance.UnityAudioSource.mute = isMute;
+                GameSetting.Instance.SetBool(GameSetting.Sets.Mute_int, isMute);
+            });
         }
     }
 }

+ 23 - 0
Unity/Assets/Scripts/Codes/Model/Client/GameSetting.cs

@@ -0,0 +1,23 @@
+using UnityEngine;
+
+namespace ET
+{
+    public class GameSetting : Singleton<GameSetting>
+    {
+        public enum Sets
+        {
+            Mute_int,
+        }
+
+        public bool GetBool(Sets sets)
+        {
+            var key = sets.ToString();
+            return PlayerPrefs.GetInt(key, 0) != 0;
+        }
+        public void SetBool(Sets sets, bool value)
+        {
+            var key = sets.ToString();
+            PlayerPrefs.SetInt(key, value ? 1 : 0);
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Codes/Model/Client/GameSetting.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 7d594d0088d9edd49a8aee392c90dd83
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 2
Unity/Assets/Scripts/Loader/MonoBehaviour/Init.cs

@@ -9,7 +9,7 @@ namespace ET
 		private void Awake()
 		{
 #if UNITY_STANDALONE_WIN
-			Screen.SetResolution(540, 960, false);
+			Screen.SetResolution(675, 1080, false);
 #endif
 #if UNITY_EDITOR
 			//Editor模式下去掉debug浮窗插件
@@ -46,7 +46,7 @@ namespace ET
 			Parser.Default.ParseArguments<Options>(args)
 				.WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
 				.WithParsed(Game.AddSingleton);
-			
+
 			Game.AddSingleton<TimeInfo>();
 			Game.AddSingleton<Logger>().ILog = new UnityLogger();
 			Game.AddSingleton<ObjectPool>();