diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2020-04-19 17:19:32 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2020-04-19 17:19:32 -0400 |
| commit | c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78 (patch) | |
| tree | ee4d51c7c1d633e11f46453ef1edd3c77c4ef9f7 /Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Audio/AudioPlayableAsset.cs | |
| download | Project-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/AudioPlayableAsset.cs')
| -rw-r--r-- | Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Audio/AudioPlayableAsset.cs | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Audio/AudioPlayableAsset.cs b/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Audio/AudioPlayableAsset.cs new file mode 100644 index 0000000..7ff40fc --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Audio/AudioPlayableAsset.cs @@ -0,0 +1,133 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Audio; +#if UNITY_EDITOR +using System.ComponentModel; +#endif +using UnityEngine.Playables; + +namespace UnityEngine.Timeline +{ + /// <summary> + /// PlayableAsset wrapper for an AudioClip in Timeline. + /// </summary> + [Serializable] +#if UNITY_EDITOR + [DisplayName("Audio Clip")] +#endif + public class AudioPlayableAsset : PlayableAsset, ITimelineClipAsset + { + [SerializeField] AudioClip m_Clip; +#pragma warning disable 649 //Field is never assigned to and will always have its default value + [SerializeField] bool m_Loop; + [SerializeField, HideInInspector] float m_bufferingTime = 0.1f; + [SerializeField] AudioClipProperties m_ClipProperties = new AudioClipProperties(); + + // the amount of time to give the clip to load prior to it's start time + internal float bufferingTime + { + get { return m_bufferingTime; } + set { m_bufferingTime = value; } + } + +#if UNITY_EDITOR + Playable m_LiveClipPlayable = Playable.Null; + +#endif + + /// <summary> + /// The audio clip to be played + /// </summary> + public AudioClip clip + { + get { return m_Clip; } + set { m_Clip = value; } + } + + /// <summary> + /// Whether the audio clip loops. + /// </summary> + /// <remarks> + /// Use this to loop the audio clip when the duration of the timeline clip exceeds that of the audio clip. + /// </remarks> + public bool loop + { + get { return m_Loop; } + set { m_Loop = value; } + } + + /// <summary> + /// Returns the duration required to play the audio clip exactly once + /// </summary> + public override double duration + { + get + { + if (m_Clip == null) + return base.duration; + + // use this instead of length to avoid rounding precision errors, + return (double)m_Clip.samples / m_Clip.frequency; + } + } + + /// <summary> + /// Returns a description of the PlayableOutputs that may be created for this asset. + /// </summary> + public override IEnumerable<PlayableBinding> outputs + { + get { yield return AudioPlayableBinding.Create(name, this); } + } + + /// <summary> + /// Creates the root of a Playable subgraph to play the audio clip. + /// </summary> + /// <param name="graph">PlayableGraph that will own the playable</param> + /// <param name="go">The GameObject that triggered the graph build</param> + /// <returns>The root playable of the subgraph</returns> + public override Playable CreatePlayable(PlayableGraph graph, GameObject go) + { + if (m_Clip == null) + return Playable.Null; + + var audioClipPlayable = AudioClipPlayable.Create(graph, m_Clip, m_Loop); + audioClipPlayable.GetHandle().SetScriptInstance(m_ClipProperties.Clone()); + +#if UNITY_EDITOR + m_LiveClipPlayable = audioClipPlayable; +#endif + + return audioClipPlayable; + } + + /// <summary> + /// Returns the capabilities of TimelineClips that contain an AudioPlayableAsset + /// </summary> + public ClipCaps clipCaps + { + get + { + return ClipCaps.ClipIn | + ClipCaps.SpeedMultiplier | + ClipCaps.Blending | + (m_Loop ? ClipCaps.Looping : ClipCaps.None); + } + } + +#if UNITY_EDITOR + internal void LiveLink() + { + if (!m_LiveClipPlayable.IsValid()) + return; + + var audioMixerProperties = m_LiveClipPlayable.GetHandle().GetObject<AudioClipProperties>(); + + if (audioMixerProperties == null) + return; + + audioMixerProperties.volume = m_ClipProperties.volume; + } + +#endif + } +} |
