A game about forced loneliness, made by TACStudios
at master 57 lines 1.5 kB view raw
1using System.Collections.Generic; 2using UnityEngine.Animations; 3#if !UNITY_2020_2_OR_NEWER 4using UnityEngine.Experimental.Animations; 5#endif 6 7using UnityEngine.Playables; 8 9namespace UnityEngine.Timeline 10{ 11 class AnimationPreviewUpdateCallback : ITimelineEvaluateCallback 12 { 13 AnimationPlayableOutput m_Output; 14 PlayableGraph m_Graph; 15 List<IAnimationWindowPreview> m_PreviewComponents; 16 17 public AnimationPreviewUpdateCallback(AnimationPlayableOutput output) 18 { 19 m_Output = output; 20 21 Playable playable = m_Output.GetSourcePlayable(); 22 if (playable.IsValid()) 23 { 24 m_Graph = playable.GetGraph(); 25 } 26 } 27 28 public void Evaluate() 29 { 30 if (!m_Graph.IsValid()) 31 return; 32 33 if (m_PreviewComponents == null) 34 FetchPreviewComponents(); 35 36 foreach (var component in m_PreviewComponents) 37 { 38 if (component != null) 39 { 40 component.UpdatePreviewGraph(m_Graph); 41 } 42 } 43 } 44 45 private void FetchPreviewComponents() 46 { 47 m_PreviewComponents = new List<IAnimationWindowPreview>(); 48 49 var animator = m_Output.GetTarget(); 50 if (animator == null) 51 return; 52 53 var gameObject = animator.gameObject; 54 m_PreviewComponents.AddRange(gameObject.GetComponents<IAnimationWindowPreview>()); 55 } 56 } 57}