浏览代码

添加声音淡入淡出

leiyasi 1 年之前
父节点
当前提交
7ce71514a1

+ 29 - 1
GameClient/Assets/Game/HotUpdate/Sound/MusicManager.cs

@@ -11,6 +11,9 @@ namespace GFGGame
         private string currentName;
         private AssetOperationHandle handle;
         private Coroutine coroutine;
+        private float storyDialogVolumn = 0.6f;
+        private float storyDialogVolumnWhenVoice = 0.17f;
+        private float storyDialogChangeValue = 0.3f;
 
         private bool _isOn = true;
         public bool isOn
@@ -54,7 +57,27 @@ namespace GFGGame
 
         private void Update() 
         {
-            
+            if (player.clip == null)
+            {
+                return;
+            }
+
+            if (VoiceManager.Instance.IsPlaying())
+            {
+                if (player.volume > storyDialogVolumnWhenVoice)
+                {
+                    player.volume -= storyDialogChangeValue * Time.deltaTime;
+                    player.volume = Mathf.Max(player.volume, storyDialogVolumnWhenVoice);
+                }
+            }
+            else
+            {
+                if (player.volume < storyDialogVolumn)
+                {
+                    player.volume += storyDialogChangeValue * Time.deltaTime;
+                    player.volume = Mathf.Min(player.volume, storyDialogVolumn);
+                }
+            }
         }
 
         public void PlayCroutine(string path, bool must = false, float volume = 1.0f)
@@ -105,5 +128,10 @@ namespace GFGGame
             handle?.Release();
             player?.Stop();
         }
+
+        public void SetDefaultStoryDialogVolume()
+        {
+            player.volume = storyDialogVolumn;
+        }
     }
 }

+ 5 - 0
GameClient/Assets/Game/HotUpdate/Sound/VoiceManager.cs

@@ -125,5 +125,10 @@ namespace GFGGame
             await Task.Delay(milliseconds);
             action?.Invoke();
         }
+
+        public bool IsPlaying()
+        {
+            return player.isPlaying;
+        }
     }
 }

+ 2 - 0
GameClient/Assets/Game/HotUpdate/Views/MainStory/StoryDialogView.cs

@@ -106,6 +106,8 @@ namespace GFGGame
         {
             base.OnShown();
             MusicManager.Instance.Stop();
+            MusicManager.Instance.SetDefaultStoryDialogVolume();
+
             if (_sceneObject == null)
             {
                 _sceneObject = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetPrefabPath("SceneStoryDialog"));