internal Transient Play(AudioClip clip, bool loop, TransientParams param) { volume = new AutomatedParameter(param.GetVolume(), 0.25f); pitch = new AutomatedParameter(param.GetPitch(), 0.25f); remainingLeftSilence = param.GetLeftSilenceLength(); remainingRightSilence = param.GetRightSilenceLength(); panStereo = new AutomatedParameter(param.GetPanStereo(), 0.25f); spatialBlend = new AutomatedParameter(param.GetSpatialBlend(), 0.25f); Source.clip = clip; Source.loop = loop; Source.volume = volume.CurrentValue; Source.pitch = pitch.CurrentValue; Source.panStereo = panStereo.CurrentValue; Source.spatialBlend = spatialBlend.CurrentValue; Source.outputAudioMixerGroup = param.GetMixerGroup(); // For some reason, Unity doesn't clamp this value so we need to // clamp it ourselves to ensure no exception will be thrown. Source.time = Mathf.Clamp(param.GetTime() * clip.length, 0, clip.length); // Play the clip right away if there is no silence to generate if (remainingLeftSilence == 0) { Source.Play(); } return(this); }
internal override void Trigger(TransientParams param) { var source = SpawnTransient(); var clip = soundbank.GetRandomClip(); source.Play(clip, false, param); }
internal override void Trigger(TransientParams param) { currentParams = param; // Start playback of the audio if (source == null) { if (param.HasSilencePadding()) { if (loop == null) { loop = StartCoroutine(Loop()); } } else { source = SpawnTransient(); source.Play(clip, true, currentParams); } } // Apply the new parameters else { source.Apply(currentParams); } }
internal Transient Apply(TransientParams param) { volume.DesiredValue = param.GetVolume(); pitch.DesiredValue = param.GetPitch(); this.panStereo.DesiredValue = param.GetPanStereo(); this.spatialBlend.DesiredValue = param.GetSpatialBlend(); return(this); }
internal override void Trigger(TransientParams param) { currentParams = param; if (loop == null) { loop = StartCoroutine(Loop()); } }
internal Factory(TransientParams p = null) { volume = p?.volume ?? FloatVariance.Range(0.8f, 1.0f); pitch = p?.pitch ?? FloatVariance.Variance(1.0f, 0.1f); normalizedTime = p?.normalizedTime ?? FloatVariance.Const(0.0f); leftSilencePadding = p?.leftSilencePadding ?? FloatVariance.Const(0.0f); rightSilencePadding = p?.rightSilencePadding ?? FloatVariance.Const(0.0f); panStereo = p?.panStereo ?? FloatVariance.Const(0.0f); spatialBlend = p?.spatialBlend ?? FloatVariance.Const(0.0f); mixerGroup = p?.mixerGroup; }
internal static AudioClipHit New(AudioClip clip, TransientParams param, Vector3?position) { var helper = New <AudioClipHit>(clip); if (position.HasValue) { helper.transform.position = position.Value; } helper.clip = clip; return(helper); }
public static void Hit(Soundbank soundbank, TransientParams param, Vector3?pos = null) { // If there is nothing to play, we don't need to do anything. if (soundbank == null) { return; } var channel = FindChannel <SoundbankHit>(soundbank) ?? SoundbankHit.New(soundbank, pos); channel.Volume = 1; channel.Trigger(param); }
public static void Hit(AudioClip clip, TransientParams param, Vector3?pos = null) { // If there is nothing to play, we don't need to do anything. if (clip == null) { return; } var channel = FindChannel <AudioClipHit>(clip) ?? AudioClipHit.New(clip, param, pos); channel.Volume = 1; channel.Trigger(param); }
public static void Hit(Soundbank soundbank) { Hit(soundbank, TransientParams.Variable2D()); }
public static void Hit(AudioClip clip) { Hit(clip, TransientParams.Variable2D()); }
public static void Loop(Soundbank soundbank) { Loop(soundbank, TransientParams.Const2D()); }
public static void Loop(AudioClip clip) { Loop(clip, TransientParams.Const2D()); }
internal override void Trigger(TransientParams param) { var source = SpawnTransient(); source.Play(clip, false, param); }
/// <summary> /// Starts, restarts, or continues playback of the sound. What action /// the helper takes exactly is up to the individual helper. /// </summary> /// <param name="param"> /// The new parameters to use for the sound. /// </param> internal abstract void Trigger(TransientParams param);
/// <summary> /// Creates a new factory initialized with either the default values or /// with the values copied from another <see cref="TransientParams"/>. /// </summary> /// <param name="audioParams"> /// The <see cref="TransientParams"/> to copy the initial state from. /// </param> /// <returns>The factory to modify.</returns> public static Factory Clone(TransientParams audioParams) { return(new Factory(audioParams)); }