No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TweenClip.cs 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.ComponentModel;
  3. using UnityEngine;
  4. using UnityEngine.Playables;
  5. using UnityEngine.Timeline;
  6. namespace Timeline.Samples
  7. {
  8. // Represents the serialized data for a clip on the Tween track
  9. [Serializable]
  10. [DisplayName("Tween Clip")]
  11. public class TweenClip : PlayableAsset, ITimelineClipAsset, IPropertyPreview
  12. {
  13. public ExposedReference<Transform> startLocation;
  14. public ExposedReference<Transform> endLocation;
  15. [Tooltip("Changes the position of the assigned object")]
  16. public bool shouldTweenPosition = true;
  17. [Tooltip("Changes the rotation of the assigned object")]
  18. public bool shouldTweenRotation = true;
  19. [Tooltip("Only keys in the [0,1] range will be used")]
  20. public AnimationCurve curve = AnimationCurve.EaseInOut(0.0f, 0.0f, 1.0f, 1.0f);
  21. // Implementation of ITimelineClipAsset. This specifies the capabilities of this timeline clip inside the editor.
  22. public ClipCaps clipCaps
  23. {
  24. get { return ClipCaps.Blending; }
  25. }
  26. // Creates the playable that represents the instance of this clip.
  27. public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
  28. {
  29. // create a new TweenBehaviour
  30. ScriptPlayable<TweenBehaviour> playable = ScriptPlayable<TweenBehaviour>.Create(graph);
  31. TweenBehaviour tween = playable.GetBehaviour();
  32. // set the behaviour's data
  33. tween.startLocation = startLocation.Resolve(graph.GetResolver());
  34. tween.endLocation = endLocation.Resolve(graph.GetResolver());
  35. tween.curve = curve;
  36. tween.shouldTweenPosition = shouldTweenPosition;
  37. tween.shouldTweenRotation = shouldTweenRotation;
  38. return playable;
  39. }
  40. // Defines which properties are changed by this playable. Those properties will be reverted in editmode
  41. // when Timeline's preview is turned off.
  42. public void GatherProperties(PlayableDirector director, IPropertyCollector driver)
  43. {
  44. const string kLocalPosition = "m_LocalPosition";
  45. const string kLocalRotation = "m_LocalRotation";
  46. driver.AddFromName<Transform>(kLocalPosition + ".x");
  47. driver.AddFromName<Transform>(kLocalPosition + ".y");
  48. driver.AddFromName<Transform>(kLocalPosition + ".z");
  49. driver.AddFromName<Transform>(kLocalRotation + ".x");
  50. driver.AddFromName<Transform>(kLocalRotation + ".y");
  51. driver.AddFromName<Transform>(kLocalRotation + ".z");
  52. driver.AddFromName<Transform>(kLocalRotation + ".w");
  53. }
  54. }
  55. }