mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-19 13:59:22 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
57 lines
1.3 KiB
C#
57 lines
1.3 KiB
C#
using System.Threading;
|
|
|
|
namespace Editor;
|
|
|
|
[DropObject( "map", "vmap" )]
|
|
partial class MapDropObject : BaseDropObject
|
|
{
|
|
private string MapName;
|
|
|
|
protected override async Task Initialize( string dragData, CancellationToken token )
|
|
{
|
|
var asset = await InstallAsset( dragData, token );
|
|
if ( asset is null )
|
|
{
|
|
if ( Package.TryParseIdent( dragData, out var ident ) )
|
|
MapName = $"{ident.org}.{ident.package}";
|
|
|
|
return;
|
|
}
|
|
|
|
if ( token.IsCancellationRequested )
|
|
return;
|
|
|
|
MapName = asset.Path;
|
|
}
|
|
|
|
public override async Task OnDrop()
|
|
{
|
|
var mapInstance = SceneEditorSession.Active.Scene.GetAllComponents<MapInstance>()
|
|
.FirstOrDefault();
|
|
|
|
GameObject gameObject;
|
|
|
|
using var scene = SceneEditorSession.Scope();
|
|
|
|
using ( SceneEditorSession.Active.UndoScope( "Drop Map" ).WithComponentChanges( mapInstance is null ? Array.Empty<Component>() : new[] { mapInstance } ).WithGameObjectCreations().Push() )
|
|
{
|
|
if ( mapInstance.IsValid() )
|
|
{
|
|
gameObject = mapInstance.GameObject;
|
|
}
|
|
else
|
|
{
|
|
gameObject = new GameObject( true, "Map" );
|
|
mapInstance = gameObject.Components.Create<MapInstance>();
|
|
}
|
|
|
|
mapInstance.MapName = MapName;
|
|
|
|
EditorScene.Selection.Clear();
|
|
EditorScene.Selection.Add( gameObject );
|
|
}
|
|
|
|
await Task.CompletedTask;
|
|
}
|
|
}
|