Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AnimationPreviewUpdateCallback.cs 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections.Generic;
  2. using UnityEngine.Animations;
  3. #if !UNITY_2020_2_OR_NEWER
  4. using UnityEngine.Experimental.Animations;
  5. #endif
  6. using UnityEngine.Playables;
  7. namespace UnityEngine.Timeline
  8. {
  9. class AnimationPreviewUpdateCallback : ITimelineEvaluateCallback
  10. {
  11. AnimationPlayableOutput m_Output;
  12. PlayableGraph m_Graph;
  13. List<IAnimationWindowPreview> m_PreviewComponents;
  14. public AnimationPreviewUpdateCallback(AnimationPlayableOutput output)
  15. {
  16. m_Output = output;
  17. Playable playable = m_Output.GetSourcePlayable();
  18. if (playable.IsValid())
  19. {
  20. m_Graph = playable.GetGraph();
  21. }
  22. }
  23. public void Evaluate()
  24. {
  25. if (!m_Graph.IsValid())
  26. return;
  27. if (m_PreviewComponents == null)
  28. FetchPreviewComponents();
  29. foreach (var component in m_PreviewComponents)
  30. {
  31. if (component != null)
  32. {
  33. component.UpdatePreviewGraph(m_Graph);
  34. }
  35. }
  36. }
  37. private void FetchPreviewComponents()
  38. {
  39. m_PreviewComponents = new List<IAnimationWindowPreview>();
  40. var animator = m_Output.GetTarget();
  41. if (animator == null)
  42. return;
  43. var gameObject = animator.gameObject;
  44. m_PreviewComponents.AddRange(gameObject.GetComponents<IAnimationWindowPreview>());
  45. }
  46. }
  47. }