public static int CreateAudioSource(string clipKey) { var source = GameObject.Instantiate(new GameObject()).AddComponent <AudioSource>(); var clip = StreamingAssetsDatabase.GetSound(clipKey); if (clip == null) { InGameDebug.Log("Couldn't find clip " + clipKey + "."); } source.clip = clip; _audioSources[_nextId] = source; _unmodifiedAudioSourceVolumes[source] = 1.0f; return(_nextId); }
public static void Set(int id, string key, DynValue value) { if (!_audioSources.ContainsKey(id)) { InGameDebug.Log("SoundManager.Set(): No AudioSource with id " + id + "."); return; } var audioSource = _audioSources[id]; switch (key.ToLower()) { case "clip": audioSource.clip = StreamingAssetsDatabase.GetSound(value.String); break; case "loop": audioSource.loop = value.Boolean; break; case "volume": _unmodifiedAudioSourceVolumes[audioSource] = (float)value.Number; if (_musicSources.ContainsKey(id)) { audioSource.volume = _unmodifiedAudioSourceVolumes[audioSource] * _musicVolume; } if (_musicSources.ContainsKey(id)) { audioSource.volume = _unmodifiedAudioSourceVolumes[audioSource] * _effectsVolume; } break; case "pitch": audioSource.pitch = (float)value.Number; break; case "mute": audioSource.mute = value.Boolean; break; case "time": audioSource.time = (float)value.Number; break; } }