Files
sbox-public/game/addons/tools/Code/Scene/SceneView/DropObjects/SoundscapeDropObject.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

61 lines
1.5 KiB
C#

using System.Threading;
namespace Editor;
[DropObject( "soundscape", "sndscape", "sndscape_c" )]
partial class SoundscapeDropObject : BaseDropObject
{
Soundscape sound;
protected override async Task Initialize( string dragData, CancellationToken token )
{
Asset asset = await InstallAsset( dragData, token );
if ( asset is null )
return;
if ( token.IsCancellationRequested )
return;
PackageStatus = "Loading Sound";
sound = asset.LoadResource<Soundscape>();
PackageStatus = null;
}
public override void OnUpdate()
{
using var scope = Gizmo.Scope( "DropObject", traceTransform );
Gizmo.Draw.Color = Color.White;
Gizmo.Draw.Sprite( Vector3.Zero, 28f * Gizmo.Settings.GizmoScale, "materials/gizmo/soundscape.png" );
if ( !string.IsNullOrWhiteSpace( PackageStatus ) )
{
Gizmo.Draw.Text( PackageStatus, new Transform( Vector3.Up * 16f ), "Inter", 14 * Application.DpiScale );
}
}
public override async Task OnDrop()
{
await WaitForLoad();
if ( sound is null )
return;
using var scene = SceneEditorSession.Scope();
using ( SceneEditorSession.Active.UndoScope( "Drop Soundscape" ).WithGameObjectCreations().Push() )
{
GameObject = new GameObject();
GameObject.Name = sound.ResourceName;
GameObject.WorldTransform = traceTransform;
var component = GameObject.Components.GetOrCreate<SoundscapeTrigger>();
component.Soundscape = sound;
EditorScene.Selection.Clear();
EditorScene.Selection.Add( GameObject );
}
}
}