Bladeren bron

Added audio mixer channel config to GameModule

James Peret 3 jaren geleden
bovenliggende
commit
c231c28f78
1 gewijzigde bestanden met toevoegingen van 8 en 0 verwijderingen
  1. 8 0
      Runtime/SoundtrackModule.cs

+ 8 - 0
Runtime/SoundtrackModule.cs

@@ -2,6 +2,7 @@ using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using UnityEngine.Audio;
 using KairoEngine.Core;
 using KairoEngine.Core.ModuleSystem;
 using Sirenix.OdinInspector;
@@ -13,12 +14,15 @@ namespace KairoEngine.SoundtrackSystem
     {
         public override string name => "Soundtrack Module";
 
+        [FoldoutGroup("@name"), NonSerialized, ShowInInspector] public AudioMixerGroup audioMixerChannel;
+
         [FoldoutGroup("@name"), NonSerialized, ShowInInspector]
         public Playlist playlist;
 
         [FoldoutGroup("@name")] public int currentTrackIndex = 0;
         [FoldoutGroup("@name")] public bool playOnStart = true;
         [FoldoutGroup("@name")] public bool showDebug = false;
+        
 
         public SoundtrackModule(GameConfig config) : base(config)
         {
@@ -40,6 +44,8 @@ namespace KairoEngine.SoundtrackSystem
             manager.audioSource2 = obj.AddComponent<AudioSource>();
             manager.audioSource1.playOnAwake = false;
             manager.audioSource2.playOnAwake = false;
+            manager.audioSource1.outputAudioMixerGroup = audioMixerChannel;
+            manager.audioSource2.outputAudioMixerGroup = audioMixerChannel;
             manager.playOnStart = this.playOnStart;
             manager.showDebug = this.showDebug;
             manager.currentTrackIndex = this.currentTrackIndex;
@@ -80,11 +86,13 @@ namespace KairoEngine.SoundtrackSystem
         public override void OnBeforeSerialize(ObjectSerializer serializer) 
         { 
             if(playlist != null) serializer.AddScriptableObject("SoundtrackModule_Playlist", playlist);
+            if(audioMixerChannel != null) serializer.AddUnityObject("SoundtrackModule_audioMixerChannel", audioMixerChannel);
         }
 
         public override void OnBeforeDeserialize(ObjectSerializer serializer) 
         { 
             playlist = (Playlist)serializer.GetScriptableObject("SoundtrackModule_Playlist");
+            audioMixerChannel = (AudioMixerGroup)serializer.GetUnityObject("SoundtrackModule_audioMixerChannel");
         }
     }