/// <summary> /// The base level private method that plays /// a sound. It creates a custom audio /// source that gives us more control over /// the sound. /// </summary> /// <returns>The sound.</returns> /// <param name="sound">Sound.</param> /// <param name="hashOverrides">Hash overrides.</param> private LgAudioSource PlaySound(DataSound sound, Hashtable hashOverrides){ GameObject soundObject = new GameObject("Sound: " + sound.GetResourceName()); LgAudioSource soundSource = soundObject.AddComponent<LgAudioSource>(); soundSource.Init(sound, transform, hashOverrides); return soundSource; }
/// <summary> /// Stops the clip. clip gets destoryed after stop /// </summary> /// <param name="clipName">Clip name.</param> public virtual void StopClip(string clipName) { if (!string.IsNullOrEmpty(clipName) && spawnedAudioSources.ContainsKey(clipName)) { LgAudioSource audioSource = spawnedAudioSources[clipName]; audioSource.Stop(); } }
/// <summary> /// The base level private method that plays /// a sound. It creates a custom audio /// source that gives us more control over /// the sound. /// </summary> private LgAudioSource PlaySound(DataSound sound, Hashtable option) { GameObject soundObject = new GameObject("Sound: " + sound.GetResourceName()); LgAudioSource soundSource = soundObject.AddComponent <LgAudioSource>(); soundSource.Init(sound, transform, option); return(soundSource); }
/// <summary> /// <para>Plays the clip. </para> /// <para>option: pass in properties (Volume, Loop, etc) for LgAudioSource. </para> /// <para>option: isSoundClipManaged (T: LgAudioManager will keep a reference to this sound clip /// and will not allow the same sound clip to be played again until the current clip is stopped or /// finished, F: same sound can be played more than once and once the sound is played there's no /// way to stop it until it finishes)</para> /// </summary> /// <param name="clipName">Sound clip name</param> /// <param name="variations">Number of sounds for the same clip</param> /// <param name="hashOverrides">Hash overrides.</param> public virtual void PlayClip(string clipName, int variations = 1, Hashtable option = null) { if (option == null) { option = new Hashtable(); } if (clipName == "") { Debug.LogError("Something trying to play a sound with an empty sound id..."); return; } DataSound sound = DataSounds.GetSoundData(clipName, variations); if (sound == null) { Debug.LogError("No such sound with id " + clipName); return; } bool isSoundClipManaged = false; // Set the default to false if (option.ContainsKey("IsSoundClipManaged")) { isSoundClipManaged = (bool)option["IsSoundClipManaged"]; } //if multip sound mode is on. just play the clip if (!isSoundClipManaged) { LgAudioSource audioSource = PlaySound(sound, option); audioSource.OnDestroyed += LgAudioSourceDestroyed; } //if multi sound mode is off. check the dicitonary for the same clip else { if (!spawnedAudioSources.ContainsKey(clipName)) { LgAudioSource audioSource = PlaySound(sound, option); spawnedAudioSources.Add(clipName, audioSource); audioSource.OnDestroyed += LgAudioSourceDestroyed; } } }