using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Audio; using wf; public class AudioMixerMgr : MonoBehaviour { public AudioMixerGroup this[AudioMixerMgr.Group group] { get { return this.group_dic_[group]; } } public AudioMixerGroup this[AudioSourceMgr.Type type] { get { switch (type) { case AudioSourceMgr.Type.Bgm: return this.group_dic_[AudioMixerMgr.Group.BGM]; case AudioSourceMgr.Type.Se: return this.group_dic_[AudioMixerMgr.Group.SE]; case AudioSourceMgr.Type.System: return this.group_dic_[AudioMixerMgr.Group.System]; case AudioSourceMgr.Type.Env: return this.group_dic_[AudioMixerMgr.Group.Env]; case AudioSourceMgr.Type.Voice: return this.group_dic_[AudioMixerMgr.Group.Voice]; case AudioSourceMgr.Type.VoiceHeroine: return this.group_dic_[AudioMixerMgr.Group.VoiceHeroine]; case AudioSourceMgr.Type.VoiceSub: return this.group_dic_[AudioMixerMgr.Group.VoiceSub]; case AudioSourceMgr.Type.VoiceExtra: return this.group_dic_[AudioMixerMgr.Group.VoiceExtra]; case AudioSourceMgr.Type.VoiceMob: return this.group_dic_[AudioMixerMgr.Group.VoiceMob]; default: return this.group_dic_[AudioMixerMgr.Group.BGM]; } } } public void Awake() { string[] array = new string[] { "Master", "Master/BGM", "Master/Dance", "Master/System", "Master/Voice", "Master/Voice/Heroine", "Master/Voice/Sub", "Master/Voice/Extra", "Master/Voice/Mob", "Master/SE", "Master/Env" }; foreach (string text in array) { AudioMixerGroup[] array3 = this.Mixer.FindMatchingGroups(text); if (array3 == null || array3.Length <= 0) { Debug.Log("オーディオ初期化エラー"); Debug.Log(text + "が失敗"); NUty.WinMessageBox(NUty.GetWindowHandle(), "オーディオ機能が利用できません", "オーディオ初期化エラー", 16); Application.Quit(); return; } } this.group_dic_ = new Dictionary(); this.group_dic_.Add(AudioMixerMgr.Group.Master, this.Mixer.FindMatchingGroups("Master")[0]); this.group_dic_.Add(AudioMixerMgr.Group.BGM, this.Mixer.FindMatchingGroups("Master/BGM")[0]); this.group_dic_.Add(AudioMixerMgr.Group.Dance, this.Mixer.FindMatchingGroups("Master/Dance")[0]); this.group_dic_.Add(AudioMixerMgr.Group.System, this.Mixer.FindMatchingGroups("Master/System")[0]); this.group_dic_.Add(AudioMixerMgr.Group.Voice, this.Mixer.FindMatchingGroups("Master/Voice")[0]); this.group_dic_.Add(AudioMixerMgr.Group.VoiceHeroine, this.Mixer.FindMatchingGroups("Master/Voice/Heroine")[0]); this.group_dic_.Add(AudioMixerMgr.Group.VoiceSub, this.Mixer.FindMatchingGroups("Master/Voice/Sub")[0]); this.group_dic_.Add(AudioMixerMgr.Group.VoiceExtra, this.Mixer.FindMatchingGroups("Master/Voice/Extra")[0]); this.group_dic_.Add(AudioMixerMgr.Group.VoiceMob, this.Mixer.FindMatchingGroups("Master/Voice/Mob")[0]); this.group_dic_.Add(AudioMixerMgr.Group.SE, this.Mixer.FindMatchingGroups("Master/SE")[0]); this.group_dic_.Add(AudioMixerMgr.Group.Env, this.Mixer.FindMatchingGroups("Master/Env")[0]); } public void Start() { this.call_start = true; foreach (AudioMixerMgr.VolumePropData volumePropData in this.VolumePropDatas) { this.Mixer.GetFloat(volumePropData.name, out volumePropData.val); volumePropData.val = Utility.DecibelToVolume(volumePropData.val); this.volume_prop_acc_.Add(volumePropData.group, volumePropData); } for (int j = 0; j < this.delay_setting_.Count; j++) { this.SetVolume(this.delay_setting_[j].Key, this.delay_setting_[j].Value); } this.delay_setting_.Clear(); } public void SetVolume(AudioMixerMgr.Group group, float volume) { if (!this.call_start) { if (this.delay_setting_ == null) { this.delay_setting_ = new List>(); } this.delay_setting_.Add(new KeyValuePair(group, volume)); return; } if (this.volume_prop_acc_[group].val != volume) { this.volume_prop_acc_[group].val = volume; this.Mixer.SetFloat(this.volume_prop_acc_[group].name, Utility.VolumeToDecibel(volume)); } } public const int kGroupMax = 11; public AudioMixer Mixer; public AudioMixerMgr.VolumePropData[] VolumePropDatas; private Dictionary volume_prop_acc_ = new Dictionary(); private Dictionary group_dic_ = new Dictionary(); private bool call_start; private List> delay_setting_; public enum Group { Master, System, BGM, Dance, Voice, VoiceHeroine, VoiceSub, VoiceExtra, VoiceMob, SE, Env } [Serializable] public class VolumePropData { public AudioMixerMgr.Group group; public string name; public float val; } }