-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleAudioWrapperSoundBank.cs
More file actions
63 lines (50 loc) · 1.94 KB
/
Copy pathSimpleAudioWrapperSoundBank.cs
File metadata and controls
63 lines (50 loc) · 1.94 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
/* Fake soundbank for SimpleAudioWrapper
*
* Usage:
* -Place on instance to the scene.
* -Add AudioClips to AudioClips array. Names should match Wwise events. */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SimpleAudioWrapperSoundBank : MonoBehaviour
{
public static SimpleAudioWrapperSoundBank instance;
[SerializeField] private AudioClip[] audioClips;
[SerializeField] private SimpleAudioWrapperSoundContainer[] soundContainers;
private Dictionary<string, AudioClip> audioClipDictionary = new Dictionary<string, AudioClip>();
private Dictionary<string, SimpleAudioWrapperSoundContainer> soundContainerDictionary = new Dictionary<string, SimpleAudioWrapperSoundContainer>();
void Awake()
{
if (instance != null && instance != this)
Destroy(gameObject);
else
instance = this;
DontDestroyOnLoad(gameObject);
//Populate audioclip dictionary for quicker search.
for (int i = 0; i < audioClips.Length; i++)
{
audioClipDictionary.Add(audioClips[i].name, audioClips[i]);
}
for(int i = 0; i < soundContainers.Length; i++)
{
soundContainerDictionary.Add(soundContainers[i].name, soundContainers[i]);
}
}
public AudioClip GetAudioClipByName(string audioClipName)
{
if (soundContainerDictionary.TryGetValue(audioClipName, out SimpleAudioWrapperSoundContainer tmpSoundContainer))
{
AudioClip tmpAudioClip;
float tmpVolume;
tmpSoundContainer.GetAudioClip(out tmpAudioClip, out tmpVolume);
return tmpAudioClip;
}
/*
if (audioClipDictionary.TryGetValue(audioClipName, out AudioClip tmpAudioClip))
{
return audioClipDictionary[audioClipName];
}*/
else
return null;
}
}