-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGameUnityAudioService.cs
More file actions
244 lines (221 loc) · 9.79 KB
/
GameUnityAudioService.cs
File metadata and controls
244 lines (221 loc) · 9.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
using AudioLib.UnityAudio;
using UnityEngine;
namespace GameSample.Audio
{
/// <summary>
/// GameAudio管理クラス (UnityAudio)
/// </summary>
public class GameUnityAudioService : IGameAudioService
{
/// <summary>
/// オーディオAPIサービス
/// </summary>
private readonly IUnityAudioApiService _unityAudioApiService;
public GameUnityAudioService()
{
// 初期生成情報
var initializeSettings = GameUnityAudioSettings.UnityAudio.InitializeSetting;
// MonoBehaviourハンドラの生成
var monoBehaviourHandlerObject = new GameObject(nameof(GameUnityAudioMonoBehaviour));
var monoBehaviourHandler = monoBehaviourHandlerObject.AddComponent<GameUnityAudioMonoBehaviour>();
Object.DontDestroyOnLoad(monoBehaviourHandlerObject);
initializeSettings.MonoBehaviourHandler = monoBehaviourHandler;
// Listenerオブジェクト取得
var listenerObject = Camera.main.gameObject;
initializeSettings.ListenerObject = listenerObject;
// サービス生成
_unityAudioApiService = new UnityAudioApiService(initializeSettings);
}
/// <summary>
/// Masterボリューム
/// </summary>
public float MasterVolume
{
get => _unityAudioApiService.GetMasterVolume();
set => _unityAudioApiService.SetMasterVolume(value);
}
/// <summary>
/// BGMボリューム
/// </summary>
public float BgmVolume
{
get => _unityAudioApiService.GetSoundSheetVolume(GameUnityAudioSettings.UnityAudio.SoundSheetName.Bgm);
set => _unityAudioApiService.SetSoundSheetVolume(GameUnityAudioSettings.UnityAudio.SoundSheetName.Bgm, value);
}
/// <summary>
/// SEボリューム
/// </summary>
public float SeVolume
{
get => _unityAudioApiService.GetSoundSheetVolume(GameUnityAudioSettings.UnityAudio.SoundSheetName.Se);
set => _unityAudioApiService.SetSoundSheetVolume(GameUnityAudioSettings.UnityAudio.SoundSheetName.Se, value);
}
/// <summary>
/// 一時停止
/// </summary>
public void Pause()
{
_unityAudioApiService.Pause();
}
/// <summary>
/// 再開
/// </summary>
public void Resume()
{
_unityAudioApiService.Resume();
}
/// <summary>
/// サウンドシートロード処理
/// </summary>
/// <param name="soundSheetName">サウンドシート名</param>
public void LoadSoundSheet(string soundSheetName)
{
UnityEngine.Debug.LogWarning("not support UnityAudio => LoadSoundSheet.");
}
/// <summary>
/// サウンドシートアンロード処理
/// </summary>
public void UnLoadAllSoundSheet()
{
UnityEngine.Debug.LogWarning("not support UnityAudio => UnLoadAllSoundSheet.");
}
/// <summary>
/// BGM全停止
/// </summary>
/// <param name="option">停止オプション</param>
public void StopAllBgm(IGameAudioService.SoundStopOption option = null)
{
var fadeTimeMs = option?.FadeTimeMs ?? 0;
_unityAudioApiService.Stop(GameUnityAudioSettings.UnityAudio.SoundSheetName.Bgm, new IUnityAudioApiService.SoundStopOption()
{
FadeTimeSec = Mathf.RoundToInt(fadeTimeMs * 0.001f),
});
}
/// <summary>
/// サウンドイベント停止
/// </summary>
/// <param name="eventName">サウンドイベント名</param>
/// <param name="option">停止オプション</param>
public void StopSoundEvent(string eventName, IGameAudioService.SoundStopOption option = null)
{
var fadeTimeMs = option?.FadeTimeMs ?? 0;
_unityAudioApiService.Stop(GameUnityAudioSettings.UnityAudio.GetSoundSheetName(eventName), new IUnityAudioApiService.SoundStopOption()
{
FadeTimeSec = Mathf.RoundToInt(fadeTimeMs * 0.001f),
});
}
/// <summary>
/// サウンドイベント再生
/// </summary>
/// <param name="eventName">サウンドイベント名</param>
/// <param name="option">再生オプション</param>
public void PlaySoundEvent(string eventName, IGameAudioService.SoundPlayOption option = null)
{
var fadeTimeMs = option?.FadeTimeMs ?? 0;
_unityAudioApiService.Play(GameUnityAudioSettings.UnityAudio.GetSoundSheetName(eventName), eventName, new IUnityAudioApiService.SoundPlayOption()
{
FadeTimeSec = Mathf.RoundToInt(fadeTimeMs * 0.001f),
});
}
/// <summary>
/// サウンドイベント再生(3D)
/// </summary>
/// <param name="eventName">サウンドイベント名</param>
/// <param name="gameObject">再生するゲームオブジェクト</param>
/// <param name="option">再生オプション</param>
public void PlaySoundEvent(string eventName, GameObject gameObject, IGameAudioService.SoundPlayOption option = null)
{
var spatial3dBlend = 1.0f; // 3D再生のブレンド値
var fadeTimeMs = option?.FadeTimeMs ?? 0;
_unityAudioApiService.Play3d(gameObject, spatial3dBlend, GameUnityAudioSettings.UnityAudio.GetSoundSheetName(eventName), eventName, new IUnityAudioApiService.SoundPlayOption()
{
FadeTimeSec = Mathf.RoundToInt(fadeTimeMs * 0.001f),
});
}
/// <summary>
/// BGMエフェクト変更
/// </summary>
/// <param name="effectType">エフェクトタイプ</param>
public void ChangeBgmEffect(IGameAudioService.EffectType effectType)
{
var soundSheetName = GameUnityAudioSettings.UnityAudio.SoundSheetName.Bgm;
switch (effectType)
{
case IGameAudioService.EffectType.Normal:
_unityAudioApiService.ChangeSoundSheetSnapshot(soundSheetName, GameUnityAudioSettings.UnityAudio.SnapshotName.Normal, 1f);
break;
case IGameAudioService.EffectType.Reverb:
_unityAudioApiService.ChangeSoundSheetSnapshot(soundSheetName, GameUnityAudioSettings.UnityAudio.SnapshotName.Reverb, 1f);
break;
case IGameAudioService.EffectType.Distortion:
_unityAudioApiService.ChangeSoundSheetSnapshot(soundSheetName, GameUnityAudioSettings.UnityAudio.SnapshotName.Distortion, 1f);
break;
}
}
/// <summary>
/// SEエフェクト変更
/// </summary>
/// <param name="effectType">エフェクトタイプ</param>
public void ChangeSeEffect(IGameAudioService.EffectType effectType)
{
var soundSheetName = GameUnityAudioSettings.UnityAudio.SoundSheetName.Se;
switch (effectType)
{
case IGameAudioService.EffectType.Normal:
_unityAudioApiService.ChangeSoundSheetSnapshot(soundSheetName, GameUnityAudioSettings.UnityAudio.SnapshotName.Normal, 1f);
break;
case IGameAudioService.EffectType.Reverb:
_unityAudioApiService.ChangeSoundSheetSnapshot(soundSheetName, GameUnityAudioSettings.UnityAudio.SnapshotName.Reverb, 1f);
break;
case IGameAudioService.EffectType.Distortion:
_unityAudioApiService.ChangeSoundSheetSnapshot(soundSheetName, GameUnityAudioSettings.UnityAudio.SnapshotName.Distortion, 1f);
break;
}
}
/// <summary>
/// ブロック遷移状態を設定する
/// </summary>
/// <param name="state">遷移状態</param>
public void SetNextBlockState(IGameAudioService.NextBlockState state)
{
UnityEngine.Debug.LogWarning("not support UnityAudio => SetNextBlockState.");
}
/// <summary>
/// ゲーム内パラメータを設定する
/// </summary>
/// <param name="eventName">サウンドイベント名</param>
/// <param name="parameterName">パラメータ名</param>
/// <param name="value">パラメータ値</param>
public void SetGameParameter(string eventName, string parameterName, float value)
{
UnityEngine.Debug.LogWarning("not support UnityAudio => SetGameParameter.");
}
/// <summary>
/// スペクトラムアナライザの設定
/// </summary>
/// <param name="eventName">サウンドイベント名</param>
/// <param name="sampleCount">サンプル数</param>
/// <returns>作成に成功したか?</returns>
public bool SetSpectrumAnalyzer(string eventName, int sampleCount)
{
// UnityAudioでは設定不要
return true;
}
/// <summary>
/// スペクトラムアナライザから周波数データを取得する
/// </summary>
/// <param name="sampleCount">サンプル数</param>
/// <param name="isConvertDecibel">デシベル値に変換するか?</param>
/// <returns></returns>
public float[] GetSpectrumData(int sampleCount, bool isConvertDecibel)
{
return _unityAudioApiService.GetBgmSpectrumData(GameUnityAudioSettings.UnityAudio.SoundSheetName.Bgm, sampleCount, isConvertDecibel);
}
}
/// <summary>
/// MonoBehaviour実行用
/// </summary>
public class GameUnityAudioMonoBehaviour : MonoBehaviour
{
}
}