123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- using UnityEngine.Playables;
- namespace UnityEngine.Timeline
- {
-
-
-
- public class ActivationControlPlayable : PlayableBehaviour
- {
-
-
-
- public enum PostPlaybackState
- {
-
-
-
- Active,
-
-
-
- Inactive,
-
-
-
- Revert
- }
- enum InitialState
- {
- Unset,
- Active,
- Inactive
- }
-
-
-
- public GameObject gameObject = null;
-
- public PostPlaybackState postPlayback = PostPlaybackState.Revert;
- InitialState m_InitialState;
-
-
-
-
-
-
-
- public static ScriptPlayable<ActivationControlPlayable> Create(PlayableGraph graph, GameObject gameObject, ActivationControlPlayable.PostPlaybackState postPlaybackState)
- {
- if (gameObject == null)
- return ScriptPlayable<ActivationControlPlayable>.Null;
- var handle = ScriptPlayable<ActivationControlPlayable>.Create(graph);
- var playable = handle.GetBehaviour();
- playable.gameObject = gameObject;
- playable.postPlayback = postPlaybackState;
- return handle;
- }
-
-
-
-
-
- public override void OnBehaviourPlay(Playable playable, FrameData info)
- {
- if (gameObject == null)
- return;
- gameObject.SetActive(true);
- }
-
-
-
-
-
- public override void OnBehaviourPause(Playable playable, FrameData info)
- {
-
-
- if (gameObject != null && info.effectivePlayState == PlayState.Paused)
- {
- gameObject.SetActive(false);
- }
- }
-
-
-
-
-
-
- public override void ProcessFrame(Playable playable, FrameData info, object userData)
- {
- if (gameObject != null)
- gameObject.SetActive(true);
- }
-
-
-
-
- public override void OnGraphStart(Playable playable)
- {
- if (gameObject != null)
- {
- if (m_InitialState == InitialState.Unset)
- m_InitialState = gameObject.activeSelf ? InitialState.Active : InitialState.Inactive;
- }
- }
-
-
-
-
- public override void OnPlayableDestroy(Playable playable)
- {
- if (gameObject == null || m_InitialState == InitialState.Unset)
- return;
- switch (postPlayback)
- {
- case PostPlaybackState.Active:
- gameObject.SetActive(true);
- break;
- case PostPlaybackState.Inactive:
- gameObject.SetActive(false);
- break;
- case PostPlaybackState.Revert:
- gameObject.SetActive(m_InitialState == InitialState.Active);
- break;
- }
- }
- }
- }
|