summaryrefslogtreecommitdiff
path: root/Library/PackageCache/com.unity.timeline@1.2.13/Runtime/Animation/AnimationPreviewUpdateCallback.cs
blob: 560f9007d4fd978384788244c5571e5dec04a35d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Collections.Generic;
using UnityEngine.Animations;
using UnityEngine.Experimental.Animations;
using UnityEngine.Playables;

namespace UnityEngine.Timeline
{
    class AnimationPreviewUpdateCallback : ITimelineEvaluateCallback
    {
        AnimationPlayableOutput m_Output;
        PlayableGraph m_Graph;
        List<IAnimationWindowPreview> m_PreviewComponents;

        public AnimationPreviewUpdateCallback(AnimationPlayableOutput output)
        {
            m_Output = output;

            Playable playable = m_Output.GetSourcePlayable();
            if (playable.IsValid())
            {
                m_Graph = playable.GetGraph();
            }
        }

        public void Evaluate()
        {
            if (!m_Graph.IsValid())
                return;

            if (m_PreviewComponents == null)
                FetchPreviewComponents();

            foreach (var component in m_PreviewComponents)
            {
                if (component != null)
                {
                    component.UpdatePreviewGraph(m_Graph);
                }
            }
        }

        private void FetchPreviewComponents()
        {
            m_PreviewComponents = new List<IAnimationWindowPreview>();

            var animator = m_Output.GetTarget();
            if (animator == null)
                return;

            var gameObject = animator.gameObject;
            m_PreviewComponents.AddRange(gameObject.GetComponents<IAnimationWindowPreview>());
        }
    }
}