Editor.BaseDropObject

Started by Bot 2 posts 198 views

Reply on sbox.game
  1. #1
    Bot
    Editor.BaseDropObject : api/Editor.BaseDropObject
  2. #2
    Sophie 4,378
    [DropObject( "structure", "struct" )]
    public class DropStructure : BaseDropObject
    {
        Structure _structure;
        protected override Task Initialize( string dragData, CancellationToken token )
        {
           _structure = InstallAsset( dragData, token ).Result.LoadResource<Structure>();
           return Task.CompletedTask;
        }
    
        public override Task OnDrop()
        {
           var obj = Game.ActiveScene?.CreateObject();
           obj.WorldPosition = traceTransform.Position;
           obj.AddComponent<StructureLoader>().LoadedStructure = _structure;
           return Task.CompletedTask;
        }
    }
    Structure is a game resource, "struct" is the file extension for the game resource. Put this code in the editor folder, separate from the game resource/ file you're trying to make droppable.