Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TimelineWindow_Selection.cs 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using UnityEngine;
  2. using UnityEngine.Playables;
  3. using UnityEngine.Timeline;
  4. namespace UnityEditor.Timeline
  5. {
  6. partial class TimelineWindow
  7. {
  8. [SerializeField]
  9. SequencePath m_SequencePath;
  10. void OnSelectionChange()
  11. {
  12. //Sanitize the inline curve selection
  13. SelectionManager.GetCurrentInlineEditorCurve()?.ValidateCurvesSelection();
  14. RefreshSelection(false);
  15. }
  16. void RefreshSelection(bool forceRebuild)
  17. {
  18. // if we're in Locked mode, keep current selection - don't use locked property because the
  19. // sequence hierarchy may need to be rebuilt and it assumes no asset == unlocked
  20. if (m_LockTracker.isLocked || (state != null && state.recording))
  21. {
  22. RestoreLastSelection(forceRebuild);
  23. return;
  24. }
  25. // selection is a TimelineAsset
  26. Object selectedObject = Selection.activeObject as TimelineAsset;
  27. if (selectedObject != null)
  28. {
  29. SetCurrentSelection(Selection.activeObject);
  30. return;
  31. }
  32. // selection is a GameObject, or a prefab with a director
  33. var selectedGO = Selection.activeGameObject;
  34. if (selectedGO != null)
  35. {
  36. bool isSceneObject = !PrefabUtility.IsPartOfPrefabAsset(selectedGO);
  37. bool hasDirector = selectedGO.GetComponent<PlayableDirector>() != null;
  38. if (isSceneObject || hasDirector)
  39. {
  40. SetCurrentSelection(selectedGO);
  41. return;
  42. }
  43. }
  44. //If not currently editing a Timeline and the selection is empty, clear selection
  45. if (Selection.activeObject == null &&
  46. state.IsEditingAnEmptyTimeline())
  47. {
  48. SetCurrentSelection(null);
  49. }
  50. // otherwise, keep the same selection.
  51. RestoreLastSelection(forceRebuild);
  52. }
  53. void RestoreLastSelection(bool forceRebuild)
  54. {
  55. state.SetCurrentSequencePath(m_SequencePath, forceRebuild);
  56. //case 1201405 and 1278598: unlock the window if there is no valid asset, since the lock button is disabled
  57. if (m_LockTracker.isLocked && state.editSequence.asset == null)
  58. m_LockTracker.isLocked = false;
  59. }
  60. void SetCurrentSelection(Object obj)
  61. {
  62. var selectedGameObject = obj as GameObject;
  63. if (selectedGameObject != null)
  64. {
  65. PlayableDirector director = TimelineUtility.GetDirectorComponentForGameObject(selectedGameObject);
  66. SetTimeline(director);
  67. }
  68. else
  69. {
  70. var selectedSequenceAsset = obj as TimelineAsset;
  71. if (selectedSequenceAsset != null)
  72. {
  73. SetTimeline(selectedSequenceAsset);
  74. }
  75. }
  76. Repaint();
  77. }
  78. }
  79. }