mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-14 17:29:23 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
48 lines
1.1 KiB
C#
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 );
|
|
}
|
|
}
|
|
}
|
|
}
|