Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

ActivationTrack.cs 2.8KB

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