/// <inheritdoc /> public override DragDropEffect OnDragDrop(ref Vector2 location, DragData data) { var result = base.OnDragDrop(ref location, data); if (result != DragDropEffect.None) { return(result); } // Check if drop file(s) if (data is DragDataFiles files) { // Import files var currentFolder = Editor.Instance.Windows.ContentWin.CurrentViewFolder; if (currentFolder != null) { Editor.Instance.ContentImporting.Import(files.Files, currentFolder); } result = DragDropEffect.Copy; } // Check if drop actor(s) else if (_dragActors.HasValidDrag) { // Import actors var currentFolder = Editor.Instance.Windows.ContentWin.CurrentViewFolder; if (currentFolder != null) { ImportActors(_dragActors, currentFolder); } _dragActors.OnDragDrop(); result = DragDropEffect.Move; } // Clear cache _validDragOver = false; return(result); }
/// <inheritdoc /> protected override DragDropEffect OnDragDropHeader(DragData data) { var result = DragDropEffect.None; Actor myActor = Actor; Actor newParent; int newOrder = -1; // Check if has no actor (only for Root Actor) if (myActor == null) { // Append to the last scene var scenes = SceneManager.Scenes; if (scenes == null || scenes.Length == 0) { throw new InvalidOperationException("No scene loaded."); } newParent = scenes[scenes.Length - 1]; } else { newParent = myActor; // Use drag positioning to change target parent and index if (_dragOverMode == DragItemPositioning.Above) { if (myActor.HasParent) { newParent = myActor.Parent; newOrder = myActor.OrderInParent; } } else if (_dragOverMode == DragItemPositioning.Below) { if (myActor.HasParent) { newParent = myActor.Parent; newOrder = myActor.OrderInParent + 1; } } } if (newParent == null) { throw new InvalidOperationException("Missing parent actor."); } // Drag actors if (_dragActors != null && _dragActors.HasValidDrag) { bool worldPositionLock = ParentWindow.GetKey(Keys.Control) == false; var singleObject = _dragActors.Objects.Count == 1; if (singleObject) { var targetActor = _dragActors.Objects[0].Actor; using (new UndoBlock(Editor.Instance.Undo, targetActor, "Change actor parent")) { targetActor.SetParent(newParent, worldPositionLock); targetActor.OrderInParent = newOrder; } } else { var targetActors = _dragActors.Objects.ConvertAll(x => x.Actor); using (new UndoMultiBlock(Editor.Instance.Undo, targetActors, "Change actors parent")) { for (int i = 0; i < targetActors.Count; i++) { var targetActor = targetActors[i]; targetActor.SetParent(newParent, worldPositionLock); targetActor.OrderInParent = newOrder; } } } result = DragDropEffect.Move; } // Drag assets else if (_dragAssets != null && _dragAssets.HasValidDrag) { for (int i = 0; i < _dragAssets.Objects.Count; i++) { var item = _dragAssets.Objects[i]; switch (item.ItemDomain) { case ContentDomain.Model: { // Create actor var model = FlaxEngine.Content.LoadAsync <Model>(item.ID); var actor = ModelActor.New(); actor.StaticFlags = Actor.StaticFlags; actor.Name = item.ShortName; actor.Model = model; actor.Transform = Actor.Transform; // Spawn Editor.Instance.SceneEditing.Spawn(actor, Actor); break; } case ContentDomain.Other: { if (item.TypeName == typeof(CollisionData).FullName) { // Create actor var actor = MeshCollider.New(); actor.StaticFlags = Actor.StaticFlags; actor.Name = item.ShortName; actor.CollisionData = FlaxEngine.Content.LoadAsync <CollisionData>(item.ID); actor.Transform = Actor.Transform; // Spawn Editor.Instance.SceneEditing.Spawn(actor, Actor); } break; } case ContentDomain.Audio: { var actor = AudioSource.New(); actor.StaticFlags = Actor.StaticFlags; actor.Name = item.ShortName; actor.Clip = FlaxEngine.Content.LoadAsync <AudioClip>(item.ID); actor.Transform = Actor.Transform; Editor.Instance.SceneEditing.Spawn(actor, Actor); break; } case ContentDomain.Prefab: { throw new NotImplementedException("Spawning prefabs"); } } } result = DragDropEffect.Move; } // Drag actor type else if (_dragActorType != null && _dragActorType.HasValidDrag) { for (int i = 0; i < _dragActorType.Objects.Count; i++) { var item = _dragActorType.Objects[i]; // Create actor var actor = FlaxEngine.Object.New(item) as Actor; if (actor == null) { Editor.LogWarning("Failed to spawn actor of type " + item.FullName); continue; } actor.StaticFlags = Actor.StaticFlags; actor.Name = item.Name; actor.Transform = Actor.Transform; // Spawn Editor.Instance.SceneEditing.Spawn(actor, Actor); } result = DragDropEffect.Move; } // Clear cache _dragActors?.OnDragDrop(); _dragAssets?.OnDragDrop(); _dragActorType?.OnDragDrop(); // Check if scene has been modified if (result != DragDropEffect.None) { var node = SceneGraphFactory.FindNode(newParent.ID) as ActorNode; node?.TreeNode.Expand(); } return(result); }