/// <summary> /// Sets the hierarchy's expanded state to only contain the current selection. /// </summary> public static void FocusTimelineWindowToSelection() { TimelineAsset asset = TimelineEditor.inspectedAsset; if (asset == null) { return; } TimelineClip[] selectedClips = TimelineEditor.selectedClips; HashSet <TrackAsset> selectedTracks = new HashSet <TrackAsset>(); foreach (TimelineClip clip in selectedClips) { #if UNITY_TIMELINE_1_5_2 selectedTracks.Add(clip.GetParentTrack()); #else selectedTracks.Add(clip.parentTrack); #endif } Object[] selectedObjects = Selection.objects; foreach (Object o in selectedObjects) { if (o is TrackAsset track) { selectedTracks.Add(track); } } HashSet <TrackAsset> parents = new HashSet <TrackAsset>(); foreach (TrackAsset track in selectedTracks) { CollectParents(track, parents); } SetExpandedStates(asset, parents); #if UNITY_TIMELINE_1_5_2 EditorWindow window = TimelineEditor.GetWindow(); #else EditorWindow window = (EditorWindow)typeof(TimelineEditor).GetProperty("window", NonPublicStatic).GetValue(null); #endif object treeView = window.GetType().GetProperty("treeView", PublicInstance).GetValue(window); treeView.GetType().GetMethod("Reload", PublicInstance).Invoke(treeView, null); }