/// <summary> /// Constructor of Vox.SoundNode. Used internally by the MixedSound class to create the sound, do not use it. /// </summary> /// <remarks> /// Constructor of Vox.SoundNode. Used internally by the MixedSound class to create the sound, do not use it. To create SoundNode use the MixedSound class. /// </remarks> public SoundNode(VoxAudioSource p_voxSource, AudioClip p_clip, bool p_loop, float p_volume, SoundLayerType p_layer, int p_id) { this._id = p_id; this._nodeVolume = p_volume; this._voxSource = p_voxSource; this._voxSource.audioSource.clip = p_clip; this._voxSource.audioSource.loop = p_loop; this._voxSource.audioSource.volume = p_volume; this.soundLayer = p_layer; }
/// <summary> /// Resume SoundNode in currentNodeList f p_layer. /// </summary> public void ResumeLayerSounds(SoundLayerType p_layer) { for (int i = 0; i < _currentNodeList.Count; i++) { if (_currentNodeList[i].soundLayer == p_layer) { _currentNodeList[i].Resume(); } } }
/// <summary> /// Stop SoundNode in currentNodeList f p_layer. /// </summary> public void StopLayerSounds(SoundLayerType p_layer) { for (int i = 0; i < _currentNodeList.Count; i++) { if (_currentNodeList[i].soundLayer == p_layer) { RemoveNode(_currentNodeList[i].id); } } }
/// <summary> /// Set volume of p_layer. /// </summary> public void SetLayerVolume(SoundLayerType p_layer, float p_volume) { _arraySoundLayerVolumes[(int)p_layer] = p_volume; for (int i = 0; i < _currentNodeList.Count; i++) { if (_currentNodeList[i].soundLayer == p_layer) { _currentNodeList[i].audioSourceVolume = _currentNodeList[i].volume * p_volume; } } }
private float GetVolumeForLayer(SoundLayerType p_layer) { switch (p_layer) { case SoundLayerType.AMBIENCE: return(_volumeAmbience); case SoundLayerType.GAMEPLAY_FX: return(_volumeGameSFX); case SoundLayerType.HUD_FX: return(_volumeUserInterfaceSFX); case SoundLayerType.MUSIC: return(_volumeBackground); default: return(1f); } }
/// <summary> /// Get volume from p_layer. /// </summary> public float GetLayerVolume(SoundLayerType p_layer) { return(_arraySoundLayerVolumes[(int)p_layer]); }
public static SoundNode Play3DSound(AudioClip p_clip, bool p_isLoop, float p_volume, GameObject p_gameObject, SoundLayerType p_layer) { return(PlaySound(p_clip, p_isLoop, p_volume, p_layer, p_gameObject.transform)); }
/// @cond #endif /// <summary> /// Private function that actually creates SoundNode. /// </summary> /// private static SoundNode PlaySound(AudioClip p_clip, bool p_isLoop, float p_volume, SoundLayerType p_layer, Transform p_target = null) { SoundNode __nodule = new SoundNode(SoundModule.instance.GetFreeVoxAudioSource(AudioModelType.DEFAULT), p_clip, p_isLoop, p_volume, p_layer, SoundModule.instance.GetNextNodeID()); if (p_target != null) { // 3D Sound __nodule.VoxVoxSource.audioSource.spatialBlend = 1; __nodule.VoxVoxSource.targetTransform = p_target; } else { // 2D Sound __nodule.VoxVoxSource.audioSource.spatialBlend = 0; } __nodule.Resume(); SoundModule.instance.AddNode(__nodule); return(__nodule); }
public static SoundNode Play2DSound(AudioClip p_clip, bool p_isLoop, float p_volume, SoundLayerType p_layer) { return(PlaySound(p_clip, p_isLoop, p_volume, p_layer, null)); }
/// <summary> /// Stop all the sounds of a Vox.SoundLayerType, removing them. /// </summary> /// <remarks> /// Stop all the sounds of a Vox.SoundLayerType, removing them. /// /// <code> /// /// public AudioClip _clip; /// /// public void PlayMonsterNoise(GameObject p_monster) /// { /// Vox.Sound.Play2DSound(_clip, p_monster, false, Vox.SoundLayerType.GAMEPLAY_FX); /// } /// /// public void RemoveAllGameplayFX() /// { /// Vox.Sound.StopLayerSounds(Vox.SoundLayerType.GAMEPLAY_FX); /// } /// /// </code> /// /// </remarks> public static void StopLayerSounds(SoundLayerType p_layer) { SoundModule.instance.StopLayerSounds(p_layer); }
/// <summary> /// Pauses all the sounds of a Vox.SoundLayerType if they were playing. /// </summary> /// <remarks> /// Pauses all the sounds of a Vox.SoundLayerType if they were playing. /// Use that instead of muting sounds if the game is paused or something similar, generally more useful for fx than music. /// /// <code> /// /// Vox.SoundNode _screamFXNode; /// public AudioClip _clip; /// /// public void PlayScream() /// { /// _screamFXNode = Vox.Sound.Play2DSound(_clip, true, Vox.SoundLayerType.GAMEPLAY_FX); /// } /// /// public void PauseGame() /// { /// Vox.Sound.PauseLayerSounds(Vox.SoundLayerType.GAMEPLAY_FX); /// } /// /// public void ResumeGame() /// { /// Vox.Sound.ResumeLayerSounds(Vox.SoundLayerType.GAMEPLAY_FX); /// } /// /// </code> /// /// </remarks> public static void PauseLayerSounds(SoundLayerType p_layer) { SoundModule.instance.PauseLayerSounds(p_layer); }
/// <summary> /// Resume all the sounds of a Vox.SoundLayerType if they were paused. /// </summary> /// <remarks> /// Resume all the sounds of a Vox.SoundLayerType if they were paused. /// Use that instead of muting sounds if the game is paused or something similar, generally more useful for fx than music. /// /// <code> /// /// Vox.SoundNode _screamFXNode; /// public AudioClip _clip; /// /// public void PlayScream() /// { /// _screamFXNode = Vox.Sound.Play2DSound(_clip, true, Vox.SoundLayerType.GAMEPLAY_FX); /// } /// /// public void PauseGame() /// { /// Vox.Sound.PauseLayerSounds(Vox.SoundLayerType.GAMEPLAY_FX); /// } /// /// public void ResumeGame() /// { /// Vox.Sound.ResumeLayerSounds(Vox.SoundLayerType.GAMEPLAY_FX); /// } /// /// </code> /// /// </remarks> public static void ResumeLayerSounds(SoundLayerType p_layer) { SoundModule.instance.ResumeLayerSounds(p_layer); }
/// <summary> /// Set the volume of the desired Vox.SoundLayerType. /// </summary> /// <remarks> /// Set the current volume which is used to control all the sounds of a Vox.SoundLayerType. /// /// <code> /// /// Vox.SoundNode _backgroundMusic; /// public AudioClip _clip; /// /// public void PlayMusic() /// { /// _backgroundMusic = Vox.Sound.Play2DSound(_clip, true, Vox.SoundLayerType.MUSIC); /// } /// /// public float MuteMusic() /// { /// return Vox.Sound.SetLayerVolume(Vox.SoundLayerType.MUSIC, 0); /// } /// /// </code> /// /// </remarks> public static void SetLayerVolume(SoundLayerType p_layer, float _volume) { SoundModule.instance.SetLayerVolume(p_layer, _volume); }
/// @endcond #endif #endregion #region Layers Management /// <summary> /// Get volume of the desired Vox.SoundLayerType. /// </summary> /// <remarks> /// Get the current volume which is used to control all the sounds of a Vox.SoundLayerType. /// /// <code> /// /// Vox.SoundNode _backgroundMusic; /// public AudioClip _clip; /// /// public void PlayMusic() /// { /// _backgroundMusic = Vox.Sound.Play2DSound(_clip, true, Vox.SoundLayerType.MUSIC); /// } /// /// public float GetMusicVolume() /// { /// return Vox.Sound.GetLayerVolume(Vox.SoundLayerType.MUSIC); /// } /// /// </code> /// /// </remarks> public static float GetLayerVolume(SoundLayerType p_layer) { return(SoundModule.instance.GetLayerVolume(p_layer)); }