| | 1 | | using UnityEngine; |
| | 2 | | using UnityEngine.Audio; |
| | 3 | | using ReorderableList; |
| | 4 | | using System.Collections.Generic; |
| | 5 | |
|
| | 6 | | public class AudioContainer : MonoBehaviour |
| | 7 | | { |
| | 8 | | [System.Serializable] |
| | 9 | | public class AudioEventList : ReorderableArray<AudioEvent> { } |
| | 10 | |
|
| | 11 | | public bool instantiateEvents = false; |
| | 12 | | public AudioMixerGroup audioMixerGroup; |
| | 13 | | [Range(0f, 1f)] |
| 2158 | 14 | | public float spatialBlend = 1f; |
| | 15 | | public bool overrideDefaults = false; |
| 2158 | 16 | | public float dopplerLevel = 1f; |
| 2158 | 17 | | public float minDistance = 1; |
| 2158 | 18 | | public float maxDistance = 500; |
| | 19 | |
|
| | 20 | | [Reorderable] |
| | 21 | | public AudioEventList audioEvents; |
| | 22 | |
|
| | 23 | | void Awake() |
| | 24 | | { |
| 2145 | 25 | | if (!overrideDefaults) |
| | 26 | | { |
| 862 | 27 | | dopplerLevel = 0.0f; |
| 862 | 28 | | minDistance = 1f; |
| 862 | 29 | | maxDistance = 400f; |
| | 30 | | } |
| | 31 | |
|
| 2145 | 32 | | if (instantiateEvents) |
| | 33 | | { |
| 28226 | 34 | | for (int i = 0; i < audioEvents.Count; i++) |
| | 35 | | { |
| 12830 | 36 | | string str = audioEvents[i].name; |
| 12830 | 37 | | AudioEvent instance = Instantiate(audioEvents[i]); |
| 12830 | 38 | | audioEvents[i] = instance; |
| 12830 | 39 | | instance.name = str; |
| | 40 | | } |
| | 41 | | } |
| | 42 | |
|
| 36958 | 43 | | foreach (AudioEvent e in audioEvents) |
| | 44 | | { |
| 16334 | 45 | | e.Initialize(this); |
| | 46 | | } |
| 2145 | 47 | | } |
| | 48 | |
|
| | 49 | | public AudioEvent GetEvent(string eventName) |
| | 50 | | { |
| 29898 | 51 | | for (int i = 0; i < audioEvents.Count; i++) |
| | 52 | | { |
| 14949 | 53 | | if (audioEvents[i].name == eventName) |
| 2990 | 54 | | return audioEvents[i]; |
| | 55 | | } |
| | 56 | |
|
| 0 | 57 | | Debug.Log($"{name}'s AudioContainer couldn't find an event called {eventName}"); |
| 0 | 58 | | return null; |
| | 59 | | } |
| | 60 | | } |