123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- 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<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.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<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 = 11;
- 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,
- VoiceHeroine,
- VoiceSub,
- VoiceExtra,
- VoiceMob,
- SE,
- Env
- }
- [Serializable]
- public class VolumePropData
- {
- public AudioMixerMgr.Group group;
- public string name;
- public float val;
- }
- }
|