mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-05-24 06:46:26 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using Editor.MapDoc;
|
|
|
|
namespace Editor.MapEditor;
|
|
|
|
[CanDrop( "sound" )]
|
|
class SoundDropTarget : IMapViewDropTarget
|
|
{
|
|
MapEntity SoundEntity { get; set; }
|
|
|
|
public void DragEnter( Package package, MapView view )
|
|
{
|
|
SoundEntity = new MapEntity();
|
|
SoundEntity.ClassName = "snd_event_point";
|
|
SetSoundFromPackage( package, SoundEntity );
|
|
}
|
|
|
|
public void DragEnter( Asset asset, MapView view )
|
|
{
|
|
SoundEntity = new MapEntity();
|
|
SoundEntity.ClassName = "snd_event_point";
|
|
SoundEntity.SetKeyValue( "soundName", 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 );
|
|
SoundEntity.Position = tr.HitPosition + tr.Normal * 16.0f;
|
|
}
|
|
|
|
public void DragLeave( MapView view )
|
|
{
|
|
if ( SoundEntity.IsValid() ) view.MapDoc.DeleteNode( SoundEntity );
|
|
}
|
|
|
|
public void DragDropped( MapView view )
|
|
{
|
|
History.MarkUndoPosition( "New Sound" );
|
|
History.KeepNew( SoundEntity );
|
|
SoundEntity = null;
|
|
}
|
|
|
|
static async void SetSoundFromPackage( Package package, MapEntity ent )
|
|
{
|
|
var asset = await AssetSystem.InstallAsync( package.FullIdent );
|
|
if ( ent.IsValid() ) ent.SetKeyValue( "soundName", asset.Path );
|
|
}
|
|
}
|