TimelineWindow_PlayableLookup.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.Playables;
  4. using UnityEngine.Timeline;
  5. namespace UnityEditor.Timeline
  6. {
  7. partial class TimelineWindow
  8. {
  9. PlayableLookup m_PlayableLookup = new PlayableLookup();
  10. class PlayableLookup
  11. {
  12. const int k_InitialDictionarySize = 10;
  13. readonly Dictionary<AnimationClip, Playable> m_AnimationClipToPlayable =
  14. new Dictionary<AnimationClip, Playable>(k_InitialDictionarySize);
  15. readonly Dictionary<AnimationClip, TimelineClip> m_AnimationClipToTimelineClip =
  16. new Dictionary<AnimationClip, TimelineClip>(k_InitialDictionarySize);
  17. public void UpdatePlayableLookup(TimelineClip clip, GameObject go, Playable p)
  18. {
  19. if (clip == null || go == null || !p.IsValid())
  20. return;
  21. if (clip.curves != null)
  22. m_AnimationClipToTimelineClip[clip.curves] = clip;
  23. UpdatePlayableLookup(clip.parentTrack.timelineAsset, clip, go, p);
  24. }
  25. public void UpdatePlayableLookup(TrackAsset track, GameObject go, Playable p)
  26. {
  27. if (track == null || go == null || !p.IsValid())
  28. return;
  29. UpdatePlayableLookup(track.timelineAsset, track, go, p);
  30. }
  31. void UpdatePlayableLookup(TimelineAsset timelineAsset, ICurvesOwner curvesOwner, GameObject go, Playable p)
  32. {
  33. var director = go.GetComponent<PlayableDirector>();
  34. var editingDirector = instance.state.editSequence.director;
  35. // No Asset mode update
  36. if (curvesOwner.curves != null && director != null && director == editingDirector &&
  37. timelineAsset == instance.state.editSequence.asset)
  38. {
  39. m_AnimationClipToPlayable[curvesOwner.curves] = p;
  40. }
  41. }
  42. public bool GetPlayableFromAnimClip(AnimationClip clip, out Playable p)
  43. {
  44. if (clip == null)
  45. {
  46. p = Playable.Null;
  47. return false;
  48. }
  49. return m_AnimationClipToPlayable.TryGetValue(clip, out p);
  50. }
  51. public TimelineClip GetTimelineClipFromCurves(AnimationClip clip)
  52. {
  53. if (clip == null)
  54. return null;
  55. TimelineClip timelineClip = null;
  56. m_AnimationClipToTimelineClip.TryGetValue(clip, out timelineClip);
  57. return timelineClip;
  58. }
  59. public void ClearPlayableLookup()
  60. {
  61. m_AnimationClipToPlayable.Clear();
  62. }
  63. }
  64. }
  65. }