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]
61 lines
1.4 KiB
C#
61 lines
1.4 KiB
C#
using System.Threading;
|
|
|
|
namespace Editor;
|
|
|
|
[DropObject( "sound", "sound", "sound_c" )]
|
|
partial class SoundDropObject : BaseDropObject
|
|
{
|
|
SoundEvent 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<SoundEvent>();
|
|
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/sound.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 Sound Point" ).WithGameObjectCreations().Push() )
|
|
{
|
|
GameObject = new GameObject();
|
|
GameObject.Name = sound.ResourceName;
|
|
GameObject.WorldTransform = traceTransform;
|
|
|
|
var component = GameObject.Components.GetOrCreate<SoundPointComponent>();
|
|
component.SoundEvent = sound;
|
|
|
|
EditorScene.Selection.Clear();
|
|
EditorScene.Selection.Add( GameObject );
|
|
}
|
|
}
|
|
}
|