Files
sbox-public/engine/Sandbox.Tools/Scene/Session/SceneEditorSession.Selection.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

48 lines
1.1 KiB
C#

using System;
namespace Editor;
public partial class SceneEditorSession
{
public SelectionSystem Selection { get; } = new SelectionSystem();
/// <summary>
/// when changing the selection, we save it as the previous, so that undo has a frame of reference
/// </summary>
string previousSavedSelection = null;
/// <summary>
/// Serlialize the current selection to a json string. The aim here is to make something we can transfer back to objects.
/// </summary>
public string SerializeSelection()
{
return Json.Serialize( Selection.OfType<GameObject>().Select( x => x.Id ).Order().ToArray() );
}
/// <summary>
/// Take a json string created by SerializeSelection and turn it into a selection
/// </summary>
public void DeserializeSelection( string selection )
{
previousSavedSelection = selection;
if ( string.IsNullOrWhiteSpace( selection ) )
{
Selection.Clear();
return;
}
var guids = Json.Deserialize<Guid[]>( selection );
Selection.Clear();
foreach ( var o in guids )
{
if ( Scene.Directory.FindByGuid( o ) is GameObject go )
{
Selection.Add( go );
}
}
}
}