AudioMixerMgr.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Audio;
  5. using wf;
  6. public class AudioMixerMgr : MonoBehaviour
  7. {
  8. public AudioMixerGroup this[AudioMixerMgr.Group group]
  9. {
  10. get
  11. {
  12. return this.group_dic_[group];
  13. }
  14. }
  15. public void Awake()
  16. {
  17. string[] array = new string[]
  18. {
  19. "Master",
  20. "Master/BGM",
  21. "Master/Dance",
  22. "Master/System",
  23. "Master/Voice",
  24. "Master/SE",
  25. "Master/Env"
  26. };
  27. foreach (string text in array)
  28. {
  29. AudioMixerGroup[] array3 = this.Mixer.FindMatchingGroups(text);
  30. if (array3 == null || array3.Length <= 0)
  31. {
  32. Debug.Log("オーディオ初期化エラー");
  33. Debug.Log(text + "が失敗");
  34. NUty.WinMessageBox(NUty.GetWindowHandle(), "オーディオ機能が利用できません", "オーディオ初期化エラー", 16);
  35. Application.Quit();
  36. return;
  37. }
  38. }
  39. this.group_dic_ = new Dictionary<AudioMixerMgr.Group, AudioMixerGroup>();
  40. this.group_dic_.Add(AudioMixerMgr.Group.Master, this.Mixer.FindMatchingGroups("Master")[0]);
  41. this.group_dic_.Add(AudioMixerMgr.Group.BGM, this.Mixer.FindMatchingGroups("Master/BGM")[0]);
  42. this.group_dic_.Add(AudioMixerMgr.Group.Dance, this.Mixer.FindMatchingGroups("Master/Dance")[0]);
  43. this.group_dic_.Add(AudioMixerMgr.Group.System, this.Mixer.FindMatchingGroups("Master/System")[0]);
  44. this.group_dic_.Add(AudioMixerMgr.Group.Voice, this.Mixer.FindMatchingGroups("Master/Voice")[0]);
  45. this.group_dic_.Add(AudioMixerMgr.Group.SE, this.Mixer.FindMatchingGroups("Master/SE")[0]);
  46. this.group_dic_.Add(AudioMixerMgr.Group.Env, this.Mixer.FindMatchingGroups("Master/Env")[0]);
  47. }
  48. public void Start()
  49. {
  50. this.call_start = true;
  51. foreach (AudioMixerMgr.VolumePropData volumePropData in this.VolumePropDatas)
  52. {
  53. this.Mixer.GetFloat(volumePropData.name, out volumePropData.val);
  54. volumePropData.val = Utility.DecibelToVolume(volumePropData.val);
  55. this.volume_prop_acc_.Add(volumePropData.group, volumePropData);
  56. }
  57. for (int j = 0; j < this.delay_setting_.Count; j++)
  58. {
  59. this.SetVolume(this.delay_setting_[j].Key, this.delay_setting_[j].Value);
  60. }
  61. this.delay_setting_.Clear();
  62. }
  63. public void SetVolume(AudioMixerMgr.Group group, float volume)
  64. {
  65. if (!this.call_start)
  66. {
  67. if (this.delay_setting_ == null)
  68. {
  69. this.delay_setting_ = new List<KeyValuePair<AudioMixerMgr.Group, float>>();
  70. }
  71. this.delay_setting_.Add(new KeyValuePair<AudioMixerMgr.Group, float>(group, volume));
  72. return;
  73. }
  74. if (this.volume_prop_acc_[group].val != volume)
  75. {
  76. this.volume_prop_acc_[group].val = volume;
  77. this.Mixer.SetFloat(this.volume_prop_acc_[group].name, Utility.VolumeToDecibel(volume));
  78. }
  79. }
  80. public const int kGroupMax = 7;
  81. public AudioMixer Mixer;
  82. public AudioMixerMgr.VolumePropData[] VolumePropDatas;
  83. private Dictionary<AudioMixerMgr.Group, AudioMixerMgr.VolumePropData> volume_prop_acc_ = new Dictionary<AudioMixerMgr.Group, AudioMixerMgr.VolumePropData>();
  84. private Dictionary<AudioMixerMgr.Group, AudioMixerGroup> group_dic_ = new Dictionary<AudioMixerMgr.Group, AudioMixerGroup>();
  85. private bool call_start;
  86. private List<KeyValuePair<AudioMixerMgr.Group, float>> delay_setting_;
  87. public enum Group
  88. {
  89. Master,
  90. System,
  91. BGM,
  92. Dance,
  93. Voice,
  94. SE,
  95. Env
  96. }
  97. [Serializable]
  98. public class VolumePropData
  99. {
  100. public AudioMixerMgr.Group group;
  101. public string name;
  102. public float val;
  103. }
  104. }