From 225f350c2fd222642d8ba4a178cad9a778ddba81 Mon Sep 17 00:00:00 2001 From: jasonm-unity Date: Thu, 24 Aug 2017 15:03:53 -0400 Subject: [PATCH] added auto-activation when in timeline clip --- .../Scripts/Timeline/AlembicShotAsset.cs | 4 +++ .../Scripts/Timeline/AlembicShotPlayable.cs | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotAsset.cs b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotAsset.cs index 9836927b7..9f973a152 100644 --- a/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotAsset.cs +++ b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotAsset.cs @@ -29,6 +29,9 @@ public class AlembicShotAsset : PlayableAsset, ITimelineClipAsset [Tooltip("Portion, in seconds, of the alembic stream used by the shot.")] [ReadOnly] public float m_AlembicLength = 0; + [Tooltip("Auto active/deactivate GameObject on Play/Pause")] + [SerializeField] public bool m_AutoActivateTarget = true; + public ClipCaps clipCaps { get { return ClipCaps.None; } } public override Playable CreatePlayable(PlayableGraph graph, GameObject owner) @@ -41,6 +44,7 @@ public override Playable CreatePlayable(PlayableGraph graph, GameObject owner) behaviour.m_EndTimeClipOff = m_EndOffset; behaviour.m_TimeScale = m_TimeScale; behaviour.m_Cycle = m_Cycle; + behaviour.m_AutoActivateTarget = m_AutoActivateTarget; return playable; } diff --git a/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotPlayable.cs b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotPlayable.cs index 8e74a5777..f2eac4c63 100644 --- a/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotPlayable.cs +++ b/AlembicImporter/Assets/UTJ/Alembic/Scripts/Timeline/AlembicShotPlayable.cs @@ -22,9 +22,12 @@ public AlembicStreamPlayer streamPlayer } } + bool m_RestoreState = false; + bool m_OrgState; public float m_StartTimeOffset; public float m_EndTimeClipOff; public float m_TimeScale; + public bool m_AutoActivateTarget; public AlembicPlaybackSettings.CycleType m_Cycle = AlembicPlaybackSettings.CycleType.Hold; public override void ProcessFrame(Playable playable, FrameData info, object playerData) @@ -44,6 +47,33 @@ public override void ProcessFrame(Playable playable, FrameData info, object play streamPlayer.ManualUpdate(); } + + public override void OnBehaviourPlay(Playable playable, FrameData info) + { + base.OnBehaviourPlay(playable, info); + + if (streamPlayer == null) + return; + + if (m_AutoActivateTarget) + { + m_RestoreState = true; + m_OrgState = streamPlayer.gameObject.activeInHierarchy; + streamPlayer.gameObject.SetActive(true); + } + } + + public override void OnBehaviourPause(Playable playable, FrameData info) + { + base.OnBehaviourPause(playable, info); + + if (streamPlayer == null) + return; + + if( m_AutoActivateTarget && m_RestoreState ) + streamPlayer.gameObject.SetActive(m_OrgState); + + } } }