// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; using System.Collections.Generic; using FlaxEditor.SceneGraph; namespace FlaxEditor.Utilities { /// /// Helper utility object that caches the selection of the editor and can restore it later. Works only for objects of type. /// public sealed class SelectionCache { private readonly List _objects = new List(); /// /// Caches selection. /// public void Cache() { _objects.Clear(); var selection = Editor.Instance.SceneEditing.Selection; for (int i = 0; i < selection.Count; i++) { _objects.Add(selection[i].ID); } } /// /// Restores selection. /// public void Restore() { if (_objects.Count == 0) { Editor.Instance.SceneEditing.Deselect(); return; } var selection = new List(_objects.Count); for (int i = 0; i < _objects.Count; i++) { var id = _objects[i]; var node = SceneGraphFactory.FindNode(id); if (node != null) selection.Add(node); } _objects.Clear(); Editor.Instance.SceneEditing.Select(selection); } } }