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 void Awake() { string[] array = new string[] { "Master", "Master/BGM", "Master/Dance", "Master/System", "Master/Voice", "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.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 = 7; 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, SE, Env } [Serializable] public class VolumePropData { public AudioMixerMgr.Group group; public string name; public float val; } }