#if LITMOTION_SUPPORT_UNITY_AUDIO using UnityEngine; using UnityEngine.Audio; namespace LitMotion.Extensions { /// /// Provides binding extension methods for AudioSource and AudioMixer. /// public static class LitMotionAudioExtensions { /// /// Create a motion data and bind it to AudioSource.volume /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToVolume(this MotionBuilder builder, AudioSource audioSource) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(audioSource); return builder.BindWithState(audioSource, static (x, target) => { target.volume = x; }); } /// /// Create a motion data and bind it to AudioSource.pitch /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToPitch(this MotionBuilder builder, AudioSource audioSource) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(audioSource); return builder.BindWithState(audioSource, static (x, target) => { target.pitch = x; }); } /// /// Create a motion data and bind it to AudioMixer exposed parameter. /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToAudioMixerFloat(this MotionBuilder builder, AudioMixer audioMixer, string name) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(audioMixer); return builder.BindWithState(audioMixer, name, static (x, target, n) => { target.SetFloat(n, x); }); } } } #endif