Singularity/Library/PackageCache/com.unity.timeline@1.6.4/Editor/Window/TimelineWindow_PlayableLook...
2024-05-06 11:45:45 -07:00

80 lines
2.8 KiB
C#

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.GetParentTrack().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();
}
}
}
}