private void Awake() { Instance = this; foreach (var sound in SoundList) { if (NameToSound.ContainsKey(sound.name)) { throw new Exception("error initializing sounds: duplicate sound name in list"); } if (sound.name.IsNullOrEmpty()) { throw new Exception("error initializing sounds: all sounds must have a name"); } NameToSound.Add(sound.name, sound); } foreach (var voice in VoiceList) { if (NameToVoice.ContainsKey(voice.name)) { throw new Exception("error initializing voice lines: duplicate name in list"); } if (voice.name.IsNullOrEmpty()) { throw new Exception("error initializing voice lines: all lines must have a name"); } } }
public static void Play(string soundName) { if (!NameToSound.ContainsKey(soundName)) { throw new Exception($"tried to play uninitialized sound {soundName}"); } Instance.Play(NameToSound[soundName]); }