Files
sbox-public/game/editor/Hammer/Code/DropTargets/SoundscapeDropTarget.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

49 lines
1.3 KiB
C#

using Editor.MapDoc;
namespace Editor.MapEditor;
[CanDrop( "sndscape" )]
class SoundscapeDropTarget : IMapViewDropTarget
{
MapEntity SoundScapeEntity { get; set; }
public void DragEnter( Package package, MapView view )
{
SoundScapeEntity = new MapEntity();
SoundScapeEntity.ClassName = "snd_soundscape";
SetSoundFromPackage( package, SoundScapeEntity );
}
public void DragEnter( Asset asset, MapView view )
{
SoundScapeEntity = new MapEntity();
SoundScapeEntity.ClassName = "snd_soundscape";
SoundScapeEntity.SetKeyValue( "soundscape", asset.Path );
}
public void DragMove( MapView view )
{
view.BuildRay( out Vector3 rayStart, out Vector3 rayEnd );
var tr = Trace.Ray( rayStart, rayEnd ).Run( view.MapDoc.World );
SoundScapeEntity.Position = tr.HitPosition + tr.Normal * 16.0f;
}
public void DragLeave( MapView view )
{
if ( SoundScapeEntity.IsValid() ) view.MapDoc.DeleteNode( SoundScapeEntity );
}
public void DragDropped( MapView view )
{
History.MarkUndoPosition( "New Soundscape" );
History.KeepNew( SoundScapeEntity );
SoundScapeEntity = null;
}
static async void SetSoundFromPackage( Package package, MapEntity ent )
{
var asset = await AssetSystem.InstallAsync( package.FullIdent );
if ( ent.IsValid() ) ent.SetKeyValue( "soundscape", asset.Path );
}
}