using UnityEngine;
using System.Collections;
using System.Collections.Generic;
// ReSharper disable once CheckNamespace
namespace DarkTonic.MasterAudio {
///
/// This class contains extension methods so you can call some Master Audio methods with less parameters directly from the Transform object.
///
public static class AudioTransformExtensions {
///
/// This method allows you to fade out all sounds of a particular Sound Group triggered by or following a Transform for X seconds.
///
/// The Transform the sound was triggered to follow or use the position of.
/// The name of the Sound Group.
/// The amount of seconds the fading will take.
public static void FadeOutSoundGroupOfTransform(this Transform sourceTrans, string sType, float fadeTime) {
MasterAudio.FadeOutSoundGroupOfTransform(sourceTrans, sType, fadeTime);
}
///
/// This will return a list of all playing Variations of a Transform
///
/// Source transform
/// List of SoundGroupVariation
public static List GetAllPlayingVariationsOfTransform(this Transform sourceTrans) {
return MasterAudio.GetAllPlayingVariationsOfTransform(sourceTrans);
}
#region Play Sound methods
///
/// This method allows you to play a sound in a Sound Group from a specific position - the position of a Transform you pass in. Returns bool indicating success (played) or not.
///
/// The name of the Sound Group to trigger a sound from.
/// The Transform whose position you want the sound to eminate from.
/// Optional - used if you want to play the sound at a reduced volume (between 0 and 1).
/// Optional - used if you want to play the sound at a specific pitch. If you do, it will override the pich and random pitch in the variation.
/// Optional - used if you want to play the sound X seconds from now instead of immediately.
/// Optional - used if you want to play a specific variation by name. Otherwise a random variation is played.
/// boolean- true indicating that the sound was either played or scheduled, false otherwise.
public static bool PlaySound3DAtTransformAndForget(this Transform sourceTrans, string sType,
float volumePercentage = 1f, float? pitch = null, float delaySoundTime = 0f, string variationName = null) {
return MasterAudio.PlaySound3DAtTransformAndForget(sType, sourceTrans, volumePercentage, pitch,
delaySoundTime, variationName);
}
///
/// This method allows you to play a sound in a Sound Group from a specific position - the position of a Transform you pass in.
///
/// The name of the Sound Group to trigger a sound from.
/// The Transform whose position you want the sound to eminate from.
/// Optional - used if you want to play the sound at a reduced volume (between 0 and 1).
/// Optional - used if you want to play the sound at a specific pitch. If you do, it will override the pich and random pitch in the variation.
/// Optional - used if you want to play the sound X seconds from now instead of immediately.
/// Optional - used if you want to play a specific variation by name. Otherwise a random variation is played.
/// PlaySoundResult - this object can be used to read if the sound played or not and also gives access to the Variation object that was used.
public static PlaySoundResult PlaySound3DAtTransform(this Transform sourceTrans, string sType,
float volumePercentage = 1f, float? pitch = null, float delaySoundTime = 0f, string variationName = null) {
return MasterAudio.PlaySound3DAtTransform(sType, sourceTrans, volumePercentage, pitch, delaySoundTime,
variationName);
}
///
/// This method allows you to play a sound in a Sound Group from a specific position - a Transform you pass in. Returns bool indicating success (played) or not.
///
/// The name of the Sound Group to trigger a sound from.
/// The Transform whose position you want the sound to eminate from.
/// Optional - used if you want to play the sound at a reduced volume (between 0 and 1).
/// Optional - used if you want to play the sound at a specific pitch. If you do, it will override the pich and random pitch in the variation.
/// Optional - used if you want to play the sound X seconds from now instead of immediately.
/// Optional - used if you want to play a specific variation by name. Otherwise a random variation is played.
/// boolean- true indicating that the sound was either played or scheduled, false otherwise.
public static bool PlaySound3DFollowTransformAndForget(this Transform sourceTrans, string sType,
float volumePercentage = 1f, float? pitch = null, float delaySoundTime = 0f, string variationName = null) {
return MasterAudio.PlaySound3DFollowTransformAndForget(sType, sourceTrans, volumePercentage, pitch,
delaySoundTime, variationName);
}
///
/// This method allows you to play a sound in a Sound Group from a specific position - a Transform you pass in, and it will follow the Transform if it moves. Returns a PlaySoundResult.
///
/// The name of the Sound Group to trigger a sound from.
/// The Transform whose position you want the sound to eminate from.
/// Optional - used if you want to play the sound at a reduced volume (between 0 and 1).
/// Optional - used if you want to play the sound at a specific pitch. If you do, it will override the pich and random pitch in the variation.
/// Optional - used if you want to play the sound X seconds from now instead of immediately.
/// Optional - used if you want to play a specific variation by name. Otherwise a random variation is played.
/// PlaySoundResult - this object can be used to read if the sound played or not and also gives access to the Variation object that was used.
public static PlaySoundResult PlaySound3DFollowTransform(this Transform sourceTrans, string sType,
float volumePercentage = 1f, float? pitch = null, float delaySoundTime = 0f, string variationName = null) {
return MasterAudio.PlaySound3DFollowTransform(sType, sourceTrans, volumePercentage, pitch, delaySoundTime,
variationName);
}
///
/// This method allows you to play a sound in a Sound Group from a specific position - a Transform you pass in. This method will not return until the sound is finished (or cannot play) to continue execution. You need to call this with StartCoroutine. The sound will not be played looped, since that could cause a Coroutine that would never end.
///
/// The name of the Sound Group to trigger a sound from.
/// The Transform whose position you want the sound to eminate from. Pass null if you want to play the sound 2D.
/// Optional - used if you want to play the sound at a reduced volume (between 0 and 1).
/// Optional - used if you want to play the sound at a specific pitch. If you do, it will override the pich and random pitch in the variation.
/// Optional - used if you want to play the sound X seconds from now instead of immediately.
/// Optional - used if you want to play a specific variation by name. Otherwise a random variation is played.
/// Optional - used to pass in the DSP time to play the sound. Normally do not use this, use the delaySoundTime param instead.
/// Optional - Code to execute when the sound is finished.
public static IEnumerator PlaySound3DAtTransformAndWaitUntilFinished(this Transform sourceTrans, string sType,
float volumePercentage = 1f, float? pitch = null, float delaySoundTime = 0f, string variationName = null,
double? timeToSchedulePlay = null, System.Action completedAction = null) {
return MasterAudio.PlaySound3DAtTransformAndWaitUntilFinished(sType, sourceTrans, volumePercentage, pitch,
delaySoundTime, variationName, timeToSchedulePlay, completedAction);
}
///
/// This method allows you to play a sound in a Sound Group from a specific position - a Transform you pass in, and it will follow the Transform if it moves. This method will not return until the sound is finished (or cannot play) to continue execution. You need to call this with StartCoroutine. The sound will not be played looped, since that could cause a Coroutine that would never end.
///
/// The name of the Sound Group to trigger a sound from.
/// The Transform whose position you want the sound to eminate from. Pass null if you want to play the sound 2D.
/// Optional - used if you want to play the sound at a reduced volume (between 0 and 1).
/// Optional - used if you want to play the sound at a specific pitch. If you do, it will override the pich and random pitch in the variation.
/// Optional - used if you want to play the sound X seconds from now instead of immediately.
/// Optional - used if you want to play a specific variation by name. Otherwise a random variation is played.
/// Optional - used to pass in the DSP time to play the sound. Normally do not use this, use the delaySoundTime param instead.
/// Optional - Code to execute when the sound is finished.
public static IEnumerator PlaySound3DFollowTransformAndWaitUntilFinished(this Transform sourceTrans,
string sType, float volumePercentage = 1f, float? pitch = null, float delaySoundTime = 0f,
string variationName = null, double? timeToSchedulePlay = null, System.Action completedAction = null) {
return MasterAudio.PlaySound3DFollowTransformAndWaitUntilFinished(sType, sourceTrans, volumePercentage,
pitch, delaySoundTime, variationName, timeToSchedulePlay, completedAction);
}
#endregion
///
/// This method allows you to pause all sounds triggered by or following a Transform.
///
/// The Transform the sound was triggered to follow or use the position of.
public static void PauseAllSoundsOfTransform(Transform sourceTrans) {
MasterAudio.PauseAllSoundsOfTransform(sourceTrans);
}
///
/// This method allows you to pause all sounds of a particular Bus triggered by or following a Transform
///
/// The Transform the sound was triggered to follow or use the position of.
/// The name of the Bus.
public static void PauseBusOfTransform(this Transform sourceTrans, string busName) {
MasterAudio.PauseBusOfTransform(sourceTrans, busName);
}
///
/// This method allows you to pause all sounds of a particular Sound Group triggered by or following a Transform.
///
/// The Transform the sound was triggered to follow or use the position of.
/// The name of the Sound Group to stop.
public static void PauseSoundGroupOfTransform(this Transform sourceTrans, string sType) {
MasterAudio.PauseSoundGroupOfTransform(sourceTrans, sType);
}
///
/// This method allows you to abruptly stop all sounds triggered by or following a Transform.
///
/// The Transform the sound was triggered to follow or use the position of.
public static void StopAllSoundsOfTransform(this Transform sourceTrans) {
MasterAudio.StopAllSoundsOfTransform(sourceTrans);
}
///
/// This method allows you to stop all sounds of a particular Bus triggered by or following a Transform
///
/// The Transform the sound was triggered to follow or use the position of.
/// The name of the Bus.
public static void StopBusOfTransform(this Transform sourceTrans, string busName) {
MasterAudio.StopBusOfTransform(sourceTrans, busName);
}
///
/// This method allows you to abruptly stop all sounds of a particular Sound Group triggered by or following a Transform.
///
/// The Transform the sound was triggered to follow or use the position of.
/// The name of the Sound Group to stop.
public static void StopSoundGroupOfTransform(this Transform sourceTrans, string sType) {
MasterAudio.StopSoundGroupOfTransform(sourceTrans, sType);
}
///
/// This method allows you to unpause all sounds triggered by or following a Transform.
///
/// The Transform the sound was triggered to follow or use the position of.
public static void UnpauseAllSoundsOfTransform(this Transform sourceTrans) {
MasterAudio.UnpauseAllSoundsOfTransform(sourceTrans);
}
///
/// This method allows you to unpause all sounds of a particular Bus triggered by or following a Transform
///
/// The Transform the sound was triggered to follow or use the position of.
/// The name of the Bus.
public static void UnpauseBusOfTransform(this Transform sourceTrans, string busName) {
MasterAudio.UnpauseBusOfTransform(sourceTrans, busName);
}
///
/// This method allows you to unpause all sounds of a particular Sound Group triggered by or following a Transform.
///
/// The Transform the sound was triggered to follow or use the position of.
/// The name of the Sound Group to stop.
public static void UnpauseSoundGroupOfTransform(this Transform sourceTrans, string sType) {
MasterAudio.UnpauseSoundGroupOfTransform(sourceTrans, sType);
}
///
/// Will return whether the Sound Group you specify is played by a Transform you pass in.
///
/// Sound Group name
/// The Transform in question
/// boolean
public static bool IsTransformPlayingSoundGroup(this Transform sourceTrans, string sType) {
return MasterAudio.IsTransformPlayingSoundGroup(sType, sourceTrans);
}
}
}