AnimationTrack.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEngine.Playables;
  4. using UnityEngine.Timeline;
  5. namespace UnityUIPlayables
  6. {
  7. public abstract class
  8. AnimationTrack<TBinding, TValueMixer, TAnimationMixerBehaviour, TAnimationBehaviour> : TrackAsset
  9. where TAnimationMixerBehaviour : AnimationMixerBehaviour<TBinding, TValueMixer, TAnimationBehaviour>, new()
  10. where TValueMixer : AnimationMixer<TBinding, TAnimationBehaviour>, new()
  11. where TBinding : Component
  12. where TAnimationBehaviour : AnimationBehaviour, new()
  13. {
  14. public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
  15. {
  16. return ScriptPlayable<TAnimationMixerBehaviour>.Create(graph, inputCount);
  17. }
  18. public override void GatherProperties(PlayableDirector director, IPropertyCollector driver)
  19. {
  20. #if UNITY_EDITOR
  21. var component = director.GetGenericBinding(this) as TBinding;
  22. if (component == null)
  23. {
  24. return;
  25. }
  26. var so = new SerializedObject(component);
  27. var iterator = so.GetIterator();
  28. while (iterator.NextVisible(true))
  29. {
  30. if (iterator.hasVisibleChildren)
  31. {
  32. continue;
  33. }
  34. driver.AddFromName<TBinding>(component.gameObject, iterator.propertyPath);
  35. }
  36. #endif
  37. base.GatherProperties(director, driver);
  38. }
  39. }
  40. }