File size: 2,866 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | using System;
using UnityEngine.Playables;
namespace UnityEngine.Timeline
{
/// <summary>
/// Track that can be used to control the active state of a GameObject.
/// </summary>
[Serializable]
[TrackClipType(typeof(ActivationPlayableAsset))]
[TrackBindingType(typeof(GameObject))]
[ExcludeFromPreset]
[TimelineHelpURL(typeof(ActivationTrack))]
public class ActivationTrack : TrackAsset
{
[SerializeField]
PostPlaybackState m_PostPlaybackState = PostPlaybackState.LeaveAsIs;
ActivationMixerPlayable m_ActivationMixer;
/// <summary>
/// Specify what state to leave the GameObject in after the Timeline has finished playing.
/// </summary>
public enum PostPlaybackState
{
/// <summary>
/// Set the GameObject to active.
/// </summary>
Active,
/// <summary>
/// Set the GameObject to Inactive.
/// </summary>
Inactive,
/// <summary>
/// Revert the GameObject to the state in was in before the Timeline was playing.
/// </summary>
Revert,
/// <summary>
/// Leave the GameObject in the state it was when the Timeline was stopped.
/// </summary>
LeaveAsIs
}
internal override bool CanCompileClips()
{
return !hasClips || base.CanCompileClips();
}
/// <summary>
/// Specifies what state to leave the GameObject in after the Timeline has finished playing.
/// </summary>
public PostPlaybackState postPlaybackState
{
get { return m_PostPlaybackState; }
set { m_PostPlaybackState = value; UpdateTrackMode(); }
}
/// <inheritdoc/>
public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
{
var mixer = ActivationMixerPlayable.Create(graph, inputCount);
m_ActivationMixer = mixer.GetBehaviour();
UpdateTrackMode();
return mixer;
}
internal void UpdateTrackMode()
{
if (m_ActivationMixer != null)
m_ActivationMixer.postPlaybackState = m_PostPlaybackState;
}
/// <inheritdoc/>
public override void GatherProperties(PlayableDirector director, IPropertyCollector driver)
{
var gameObject = GetGameObjectBinding(director);
if (gameObject != null)
{
driver.AddFromName(gameObject, "m_IsActive");
}
}
/// <inheritdoc/>
protected override void OnCreateClip(TimelineClip clip)
{
clip.displayName = "Active";
base.OnCreateClip(clip);
}
}
}
|