123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- 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<AudioMixerMgr.Group, AudioMixerGroup>();
- 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<KeyValuePair<AudioMixerMgr.Group, float>>();
- }
- this.delay_setting_.Add(new KeyValuePair<AudioMixerMgr.Group, float>(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<AudioMixerMgr.Group, AudioMixerMgr.VolumePropData> volume_prop_acc_ = new Dictionary<AudioMixerMgr.Group, AudioMixerMgr.VolumePropData>();
- private Dictionary<AudioMixerMgr.Group, AudioMixerGroup> group_dic_ = new Dictionary<AudioMixerMgr.Group, AudioMixerGroup>();
- private bool call_start;
- private List<KeyValuePair<AudioMixerMgr.Group, float>> 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;
- }
- }
|