mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-03 09:18:43 -04:00
* Fix native resource networking Native resource networking never properly worked, because it relied on ids that may not exist on a connecting client. - `Resource.ResourceId` is now Obsolete - Added `internal Resource.ResourceIdLong` - Networking now uses the 64 bit id - Register all Resource Paths during package load, so networking for native packages works even if they are not loaded - Client automatically loads networked resource if not cached - Clothing container now serializes path instead of ID but maintains backwards compatibility. - Drop ResourceId usage in tools
101 lines
2.3 KiB
C#
101 lines
2.3 KiB
C#
using System.Threading;
|
|
|
|
namespace Editor;
|
|
|
|
[DropObject( "prefab", "prefab", "prefab_c" )]
|
|
partial class PrefabDropObject : BaseDropObject
|
|
{
|
|
private IDisposable undoScope;
|
|
|
|
protected override async Task Initialize( string dragData, CancellationToken token )
|
|
{
|
|
Asset asset = await InstallAsset( dragData, token );
|
|
|
|
if ( asset is null )
|
|
return;
|
|
|
|
if ( token.IsCancellationRequested )
|
|
return;
|
|
|
|
var pf = asset.LoadResource<PrefabFile>();
|
|
if ( pf is null ) return;
|
|
|
|
if ( SceneEditorSession.Active.Scene is PrefabScene prefabScene )
|
|
{
|
|
var currentPf = prefabScene.ToPrefabFile();
|
|
if ( currentPf == pf )
|
|
{
|
|
Log.Warning( "Cannot place the same prefab in itself." );
|
|
return;
|
|
}
|
|
}
|
|
|
|
// We should REALLY be scoped over whatever scene we're dragging over
|
|
using ( SceneEditorSession.Scope() )
|
|
{
|
|
undoScope = SceneEditorSession.Active.UndoScope( "Drop Prefab" ).WithGameObjectCreations().Push();
|
|
|
|
var go = SceneUtility.GetPrefabScene( pf );
|
|
GameObject = go.Clone();
|
|
GameObject.Flags = GameObjectFlags.NotSaved | GameObjectFlags.Hidden;
|
|
GameObject.Tags.Add( "isdragdrop" );
|
|
|
|
Bounds = GameObject.GetLocalBounds();
|
|
|
|
if ( Bounds.Size.Length < 4 )
|
|
Bounds = BBox.FromPositionAndSize( 0, 4 );
|
|
|
|
PivotPosition = Bounds.ClosestPoint( Vector3.Down * 10000 );
|
|
Rotation = GameObject.WorldRotation;
|
|
Scale = GameObject.WorldScale;
|
|
}
|
|
}
|
|
|
|
public override void OnUpdate()
|
|
{
|
|
if ( GameObject.IsValid() )
|
|
{
|
|
GameObject.WorldTransform = traceTransform;
|
|
}
|
|
|
|
using var scope = Gizmo.Scope( "DropObject", traceTransform );
|
|
|
|
Gizmo.Draw.Color = Color.White.WithAlpha( 0.3f );
|
|
Gizmo.Draw.LineBBox( Bounds );
|
|
|
|
Gizmo.Draw.Color = Color.White;
|
|
|
|
if ( !string.IsNullOrWhiteSpace( PackageStatus ) )
|
|
{
|
|
Gizmo.Draw.Text( PackageStatus, new Transform( Bounds.Center ), "Inter", 12 );
|
|
}
|
|
}
|
|
|
|
public override async Task OnDrop()
|
|
{
|
|
await WaitForLoad();
|
|
|
|
if ( !GameObject.IsValid() )
|
|
return;
|
|
|
|
GameObject.WorldTransform = traceTransform;
|
|
|
|
GameObject.Flags = GameObjectFlags.None;
|
|
GameObject.Tags.Remove( "isdragdrop" );
|
|
|
|
EditorScene.Selection.Clear();
|
|
EditorScene.Selection.Add( GameObject );
|
|
|
|
undoScope.Dispose();
|
|
undoScope = null;
|
|
|
|
GameObject = null;
|
|
}
|
|
|
|
public override void OnDestroy()
|
|
{
|
|
GameObject?.Destroy();
|
|
GameObject = null;
|
|
}
|
|
}
|