TimelineWindow_PlayableLookup.cs
2.75 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
namespace UnityEditor.Timeline
{
partial class TimelineWindow
{
PlayableLookup m_PlayableLookup = new PlayableLookup();
class PlayableLookup
{
const int k_InitialDictionarySize = 10;
readonly Dictionary<AnimationClip, Playable> m_AnimationClipToPlayable =
new Dictionary<AnimationClip, Playable>(k_InitialDictionarySize);
readonly Dictionary<AnimationClip, TimelineClip> m_AnimationClipToTimelineClip =
new Dictionary<AnimationClip, TimelineClip>(k_InitialDictionarySize);
public void UpdatePlayableLookup(TimelineClip clip, GameObject go, Playable p)
{
if (clip == null || go == null || !p.IsValid())
return;
if (clip.curves != null)
m_AnimationClipToTimelineClip[clip.curves] = clip;
UpdatePlayableLookup(clip.parentTrack.timelineAsset, clip, go, p);
}
public void UpdatePlayableLookup(TrackAsset track, GameObject go, Playable p)
{
if (track == null || go == null || !p.IsValid())
return;
UpdatePlayableLookup(track.timelineAsset, track, go, p);
}
void UpdatePlayableLookup(TimelineAsset timelineAsset, ICurvesOwner curvesOwner, GameObject go, Playable p)
{
var director = go.GetComponent<PlayableDirector>();
var editingDirector = instance.state.editSequence.director;
// No Asset mode update
if (curvesOwner.curves != null && director != null && director == editingDirector &&
timelineAsset == instance.state.editSequence.asset)
{
m_AnimationClipToPlayable[curvesOwner.curves] = p;
}
}
public bool GetPlayableFromAnimClip(AnimationClip clip, out Playable p)
{
if (clip == null)
{
p = Playable.Null;
return false;
}
return m_AnimationClipToPlayable.TryGetValue(clip, out p);
}
public TimelineClip GetTimelineClipFromCurves(AnimationClip clip)
{
if (clip == null)
return null;
TimelineClip timelineClip = null;
m_AnimationClipToTimelineClip.TryGetValue(clip, out timelineClip);
return timelineClip;
}
public void ClearPlayableLookup()
{
m_AnimationClipToPlayable.Clear();
}
}
}
}