// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2015/03/21 18:43
using UnityEngine.Audio;
namespace DG.Tweening
{
///
/// Methods that extend known Unity objects and allow to directly create and control tweens from their instances.
/// These, as all DOTween50 methods, require Unity 5.0 or later.
///
public static class ShortcutExtensions
{
#region AudioMixerGroup
/// Tweens an AudioMixer's exposed float to the given value.
/// Also stores the AudioMixer as the tween's target so it can be used for filtered operations.
/// Note that you need to manually expose a float in an AudioMixerGroup in order to be able to tween it from an AudioMixer.
/// Name given to the exposed float to set
/// The end value to reachThe duration of the tween
public static Tweener DOSetFloat(this AudioMixer target, string floatName, float endValue, float duration)
{
return DOTween.To(()=> {
float currVal;
target.GetFloat(floatName, out currVal);
return currVal;
}, x=> target.SetFloat(floatName, x), endValue, duration)
.SetTarget(target);
}
#endregion
#region Operation Shortcuts
///
/// Completes all tweens that have this target as a reference
/// (meaning tweens that were started from this target, or that had this target added as an Id)
/// and returns the total number of tweens completed
/// (meaning the tweens that don't have infinite loops and were not already complete)
///
public static int DOComplete(this AudioMixer target)
{
return DOTween.Complete(target);
}
///
/// Kills all tweens that have this target as a reference
/// (meaning tweens that were started from this target, or that had this target added as an Id)
/// and returns the total number of tweens killed.
///
/// If TRUE completes the tween before killing it
public static int DOKill(this AudioMixer target, bool complete = false)
{
// int tot = complete ? DOTween.CompleteAndReturnKilledTot(target) : 0;
// return tot + DOTween.Kill(target);
return DOTween.Kill(target, complete);
}
///
/// Flips the direction (backwards if it was going forward or viceversa) of all tweens that have this target as a reference
/// (meaning tweens that were started from this target, or that had this target added as an Id)
/// and returns the total number of tweens flipped.
///
public static int DOFlip(this AudioMixer target)
{
return DOTween.Flip(target);
}
///
/// Sends to the given position all tweens that have this target as a reference
/// (meaning tweens that were started from this target, or that had this target added as an Id)
/// and returns the total number of tweens involved.
///
/// Time position to reach
/// (if higher than the whole tween duration the tween will simply reach its end)
/// If TRUE will play the tween after reaching the given position, otherwise it will pause it
public static int DOGoto(this AudioMixer target, float to, bool andPlay = false)
{
return DOTween.Goto(target, to, andPlay);
}
///
/// Pauses all tweens that have this target as a reference
/// (meaning tweens that were started from this target, or that had this target added as an Id)
/// and returns the total number of tweens paused.
///
public static int DOPause(this AudioMixer target)
{
return DOTween.Pause(target);
}
///
/// Plays all tweens that have this target as a reference
/// (meaning tweens that were started from this target, or that had this target added as an Id)
/// and returns the total number of tweens played.
///
public static int DOPlay(this AudioMixer target)
{
return DOTween.Play(target);
}
///
/// Plays backwards all tweens that have this target as a reference
/// (meaning tweens that were started from this target, or that had this target added as an Id)
/// and returns the total number of tweens played.
///
public static int DOPlayBackwards(this AudioMixer target)
{
return DOTween.PlayBackwards(target);
}
///
/// Plays forward all tweens that have this target as a reference
/// (meaning tweens that were started from this target, or that had this target added as an Id)
/// and returns the total number of tweens played.
///
public static int DOPlayForward(this AudioMixer target)
{
return DOTween.PlayForward(target);
}
///
/// Restarts all tweens that have this target as a reference
/// (meaning tweens that were started from this target, or that had this target added as an Id)
/// and returns the total number of tweens restarted.
///
public static int DORestart(this AudioMixer target)
{
return DOTween.RestartAll(target);
}
///
/// Rewinds all tweens that have this target as a reference
/// (meaning tweens that were started from this target, or that had this target added as an Id)
/// and returns the total number of tweens rewinded.
///
public static int DORewind(this AudioMixer target)
{
return DOTween.RewindAll(target);
}
///
/// Toggles the paused state (plays if it was paused, pauses if it was playing) of all tweens that have this target as a reference
/// (meaning tweens that were started from this target, or that had this target added as an Id)
/// and returns the total number of tweens involved.
///
public static int DOTogglePause(this AudioMixer target)
{
return DOTween.TogglePause(target);
}
#endregion
}
}