From c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 19 Apr 2020 17:19:32 -0400 Subject: Inital commit --- .../Runtime/Playables/TimeControlPlayable.cs | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Playables/TimeControlPlayable.cs (limited to 'Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Playables/TimeControlPlayable.cs') diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Playables/TimeControlPlayable.cs b/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Playables/TimeControlPlayable.cs new file mode 100644 index 0000000..68ec80d --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Playables/TimeControlPlayable.cs @@ -0,0 +1,85 @@ +using UnityEngine.Playables; + +namespace UnityEngine.Timeline +{ + /// + /// A PlayableBehaviour that manages a component that implements the ITimeControl interface + /// + public class TimeControlPlayable : PlayableBehaviour + { + ITimeControl m_timeControl; + + bool m_started; + + /// + /// Creates a Playable with a TimeControlPlayable behaviour attached + /// + /// The PlayableGraph to inject the Playable into. + /// + /// + public static ScriptPlayable Create(PlayableGraph graph, ITimeControl timeControl) + { + if (timeControl == null) + return ScriptPlayable.Null; + + var handle = ScriptPlayable.Create(graph); + handle.GetBehaviour().Initialize(timeControl); + return handle; + } + + /// + /// Initializes the behaviour + /// + /// Component that implements the ITimeControl interface + public void Initialize(ITimeControl timeControl) + { + m_timeControl = timeControl; + } + + /// + /// This function is called during the PrepareFrame phase of the PlayableGraph. + /// + /// The Playable that owns the current PlayableBehaviour. + /// A FrameData structure that contains information about the current frame context. + public override void PrepareFrame(Playable playable, FrameData info) + { + Debug.Assert(m_started, "PrepareFrame has been called without OnControlTimeStart being called first."); + if (m_timeControl != null) + m_timeControl.SetTime(playable.GetTime()); + } + + /// + /// This function is called when the Playable play state is changed to Playables.PlayState.Playing. + /// + /// The Playable that owns the current PlayableBehaviour. + /// A FrameData structure that contains information about the current frame context. + public override void OnBehaviourPlay(Playable playable, FrameData info) + { + if (m_timeControl == null) + return; + + if (!m_started) + { + m_timeControl.OnControlTimeStart(); + m_started = true; + } + } + + /// + /// This function is called when the Playable play state is changed to PlayState.Paused. + /// + /// The playable this behaviour is attached to. + /// A FrameData structure that contains information about the current frame context. + public override void OnBehaviourPause(Playable playable, FrameData info) + { + if (m_timeControl == null) + return; + + if (m_started) + { + m_timeControl.OnControlTimeStop(); + m_started = false; + } + } + } +} -- cgit v1.2.3