summaryrefslogtreecommitdiff
path: root/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Audio/AudioTrack.cs
diff options
context:
space:
mode:
authorAndrew Lee <alee14498@protonmail.com>2020-04-19 17:19:32 -0400
committerAndrew Lee <alee14498@protonmail.com>2020-04-19 17:19:32 -0400
commitc55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78 (patch)
treeee4d51c7c1d633e11f46453ef1edd3c77c4ef9f7 /Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Audio/AudioTrack.cs
downloadProject-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.tar.gz
Project-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.tar.bz2
Project-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.zip
Inital commit
Diffstat (limited to 'Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Audio/AudioTrack.cs')
-rw-r--r--Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Audio/AudioTrack.cs129
1 files changed, 129 insertions, 0 deletions
diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Audio/AudioTrack.cs b/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Audio/AudioTrack.cs
new file mode 100644
index 0000000..d35fac6
--- /dev/null
+++ b/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Audio/AudioTrack.cs
@@ -0,0 +1,129 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine.Audio;
+using UnityEngine.Playables;
+
+namespace UnityEngine.Timeline
+{
+ /// <summary>
+ /// A Timeline track that can play AudioClips.
+ /// </summary>
+ [Serializable]
+ [TrackClipType(typeof(AudioPlayableAsset), false)]
+ [TrackBindingType(typeof(AudioSource))]
+ [ExcludeFromPreset]
+ public class AudioTrack : TrackAsset
+ {
+ [SerializeField]
+ AudioMixerProperties m_TrackProperties = new AudioMixerProperties();
+
+#if UNITY_EDITOR
+ Playable m_LiveMixerPlayable = Playable.Null;
+
+#endif
+
+ /// <summary>
+ /// Create an TimelineClip for playing an AudioClip on this track.
+ /// </summary>
+ /// <param name="clip">The audio clip to play</param>
+ /// <returns>A TimelineClip with an AudioPlayableAsset asset.</returns>
+ public TimelineClip CreateClip(AudioClip clip)
+ {
+ if (clip == null)
+ return null;
+
+ var newClip = CreateDefaultClip();
+
+ var audioAsset = newClip.asset as AudioPlayableAsset;
+ if (audioAsset != null)
+ audioAsset.clip = clip;
+
+ newClip.duration = clip.length;
+ newClip.displayName = clip.name;
+
+ return newClip;
+ }
+
+ internal override Playable CompileClips(PlayableGraph graph, GameObject go, IList<TimelineClip> timelineClips, IntervalTree<RuntimeElement> tree)
+ {
+ var clipBlender = AudioMixerPlayable.Create(graph, timelineClips.Count);
+
+#if UNITY_EDITOR
+ clipBlender.GetHandle().SetScriptInstance(m_TrackProperties.Clone());
+ m_LiveMixerPlayable = clipBlender;
+#else
+ if (hasCurves)
+ clipBlender.GetHandle().SetScriptInstance(m_TrackProperties.Clone());
+#endif
+
+ for (int i = 0; i < timelineClips.Count; i++)
+ {
+ var c = timelineClips[i];
+ var asset = c.asset as PlayableAsset;
+ if (asset == null)
+ continue;
+
+ var buffer = 0.1f;
+ var audioAsset = c.asset as AudioPlayableAsset;
+ if (audioAsset != null)
+ buffer = audioAsset.bufferingTime;
+
+ var source = asset.CreatePlayable(graph, go);
+ if (!source.IsValid())
+ continue;
+
+ if (source.IsPlayableOfType<AudioClipPlayable>())
+ {
+ // Enforce initial values on all clips
+ var audioClipPlayable = (AudioClipPlayable)source;
+ var audioClipProperties = audioClipPlayable.GetHandle().GetObject<AudioClipProperties>();
+
+ audioClipPlayable.SetVolume(Mathf.Clamp01(m_TrackProperties.volume * audioClipProperties.volume));
+ audioClipPlayable.SetStereoPan(Mathf.Clamp(m_TrackProperties.stereoPan, -1.0f, 1.0f));
+ audioClipPlayable.SetSpatialBlend(Mathf.Clamp01(m_TrackProperties.spatialBlend));
+ }
+
+ tree.Add(new ScheduleRuntimeClip(c, source, clipBlender, buffer));
+ graph.Connect(source, 0, clipBlender, i);
+ source.SetSpeed(c.timeScale);
+ source.SetDuration(c.extrapolatedDuration);
+ clipBlender.SetInputWeight(source, 1.0f);
+ }
+
+ ConfigureTrackAnimation(tree, go, clipBlender);
+
+ return clipBlender;
+ }
+
+ /// <inheritdoc/>
+ public override IEnumerable<PlayableBinding> outputs
+ {
+ get { yield return AudioPlayableBinding.Create(name, this); }
+ }
+
+#if UNITY_EDITOR
+ internal void LiveLink()
+ {
+ if (!m_LiveMixerPlayable.IsValid())
+ return;
+
+ var audioMixerProperties = m_LiveMixerPlayable.GetHandle().GetObject<AudioMixerProperties>();
+
+ if (audioMixerProperties == null)
+ return;
+
+ audioMixerProperties.volume = m_TrackProperties.volume;
+ audioMixerProperties.stereoPan = m_TrackProperties.stereoPan;
+ audioMixerProperties.spatialBlend = m_TrackProperties.spatialBlend;
+ }
+
+#endif
+
+ void OnValidate()
+ {
+ m_TrackProperties.volume = Mathf.Clamp01(m_TrackProperties.volume);
+ m_TrackProperties.stereoPan = Mathf.Clamp(m_TrackProperties.stereoPan, -1.0f, 1.0f);
+ m_TrackProperties.spatialBlend = Mathf.Clamp01(m_TrackProperties.spatialBlend);
+ }
+ }
+}