Select all assets and scripts that are dropped in the tree panel.

This commit is contained in:
Chandler Cox
2024-06-18 21:46:22 -05:00
parent 0d8691045b
commit 919e118a2f
3 changed files with 37 additions and 2 deletions

View File

@@ -160,16 +160,23 @@ namespace FlaxEditor.Windows.Assets
var result = base.OnDragDrop(ref location, data); var result = base.OnDragDrop(ref location, data);
if (result == DragDropEffect.None) if (result == DragDropEffect.None)
{ {
_window._isDragging = true;
// Drag assets // Drag assets
if (_dragAssets != null && _dragAssets.HasValidDrag) if (_dragAssets != null && _dragAssets.HasValidDrag)
{ {
List<SceneGraphNode> graphNodes = new List<SceneGraphNode>();
for (int i = 0; i < _dragAssets.Objects.Count; i++) for (int i = 0; i < _dragAssets.Objects.Count; i++)
{ {
var item = _dragAssets.Objects[i]; var item = _dragAssets.Objects[i];
var actor = item.OnEditorDrop(this); var actor = item.OnEditorDrop(this);
actor.Name = item.ShortName; actor.Name = item.ShortName;
_window.Spawn(actor); _window.Spawn(actor);
var graphNode = _window.Graph.Root.Find(actor);;
if (graphNode != null)
graphNodes.Add(graphNode);
} }
if (graphNodes.Count > 0)
_window.Select(graphNodes);
result = DragDropEffect.Move; result = DragDropEffect.Move;
} }
// Drag actor type // Drag actor type
@@ -213,6 +220,7 @@ namespace FlaxEditor.Windows.Assets
// Drag script item // Drag script item
else if (_dragScriptItems != null && _dragScriptItems.HasValidDrag) else if (_dragScriptItems != null && _dragScriptItems.HasValidDrag)
{ {
List<SceneGraphNode> graphNodes = new List<SceneGraphNode>();
for (int i = 0; i < _dragScriptItems.Objects.Count; i++) for (int i = 0; i < _dragScriptItems.Objects.Count; i++)
{ {
var item = _dragScriptItems.Objects[i]; var item = _dragScriptItems.Objects[i];
@@ -227,8 +235,13 @@ namespace FlaxEditor.Windows.Assets
} }
actor.Name = actorType.Name; actor.Name = actorType.Name;
_window.Spawn(actor); _window.Spawn(actor);
var graphNode = _window.Graph.Root.Find(actor);;
if (graphNode != null)
graphNodes.Add(graphNode);
} }
} }
if (graphNodes.Count > 0)
_window.Select(graphNodes);
result = DragDropEffect.Move; result = DragDropEffect.Move;
} }
_dragHandlers.OnDragDrop(null); _dragHandlers.OnDragDrop(null);

View File

@@ -42,6 +42,7 @@ namespace FlaxEditor.Windows.Assets
private bool _liveReload = false; private bool _liveReload = false;
private bool _isUpdatingSelection, _isScriptsReloading; private bool _isUpdatingSelection, _isScriptsReloading;
private DateTime _modifiedTime = DateTime.MinValue; private DateTime _modifiedTime = DateTime.MinValue;
private bool _isDragging = false;
/// <summary> /// <summary>
/// Gets the prefab hierarchy tree control. /// Gets the prefab hierarchy tree control.
@@ -273,11 +274,16 @@ namespace FlaxEditor.Windows.Assets
return true; return true;
} }
if (button == MouseButton.Left && _treePanel.ContainsPoint(ref location)) if (button == MouseButton.Left && _treePanel.ContainsPoint(ref location) && !_isDragging)
{ {
_tree.Deselect(); _tree.Deselect();
return true; return true;
} }
if (_isDragging)
{
_isDragging = false;
return true;
}
return false; return false;
} }

View File

@@ -33,6 +33,7 @@ namespace FlaxEditor.Windows
private DragControlType _dragControlType; private DragControlType _dragControlType;
private DragScriptItems _dragScriptItems; private DragScriptItems _dragScriptItems;
private DragHandlers _dragHandlers; private DragHandlers _dragHandlers;
private bool _isDropping = false;
/// <summary> /// <summary>
/// Scene tree panel. /// Scene tree panel.
@@ -356,10 +357,12 @@ namespace FlaxEditor.Windows
if (buttons == MouseButton.Left) if (buttons == MouseButton.Left)
{ {
if (Editor.StateMachine.CurrentState.CanEditScene) if (Editor.StateMachine.CurrentState.CanEditScene && !_isDropping)
{ {
Editor.SceneEditing.Deselect(); Editor.SceneEditing.Deselect();
} }
if (_isDropping)
_isDropping = false;
return true; return true;
} }
@@ -439,9 +442,11 @@ namespace FlaxEditor.Windows
var result = base.OnDragDrop(ref location, data); var result = base.OnDragDrop(ref location, data);
if (result == DragDropEffect.None) if (result == DragDropEffect.None)
{ {
_isDropping = true;
// Drag assets // Drag assets
if (_dragAssets != null && _dragAssets.HasValidDrag) if (_dragAssets != null && _dragAssets.HasValidDrag)
{ {
List<SceneGraphNode> graphNodes = new List<SceneGraphNode>();
for (int i = 0; i < _dragAssets.Objects.Count; i++) for (int i = 0; i < _dragAssets.Objects.Count; i++)
{ {
var item = _dragAssets.Objects[i]; var item = _dragAssets.Objects[i];
@@ -453,8 +458,13 @@ namespace FlaxEditor.Windows
var actor = item.OnEditorDrop(this); var actor = item.OnEditorDrop(this);
actor.Name = item.ShortName; actor.Name = item.ShortName;
Level.SpawnActor(actor); Level.SpawnActor(actor);
var graphNode = Editor.Scene.GetActorNode(actor.ID);
if (graphNode != null)
graphNodes.Add(graphNode);
Editor.Scene.MarkSceneEdited(actor.Scene); Editor.Scene.MarkSceneEdited(actor.Scene);
} }
if (graphNodes.Count > 0)
Editor.SceneEditing.Select(graphNodes);
result = DragDropEffect.Move; result = DragDropEffect.Move;
} }
// Drag actor type // Drag actor type
@@ -500,6 +510,7 @@ namespace FlaxEditor.Windows
// Drag script item // Drag script item
else if (_dragScriptItems != null && _dragScriptItems.HasValidDrag) else if (_dragScriptItems != null && _dragScriptItems.HasValidDrag)
{ {
List<SceneGraphNode> graphNodes = new List<SceneGraphNode>();
for (int i = 0; i < _dragScriptItems.Objects.Count; i++) for (int i = 0; i < _dragScriptItems.Objects.Count; i++)
{ {
var item = _dragScriptItems.Objects[i]; var item = _dragScriptItems.Objects[i];
@@ -514,9 +525,14 @@ namespace FlaxEditor.Windows
} }
actor.Name = actorType.Name; actor.Name = actorType.Name;
Level.SpawnActor(actor); Level.SpawnActor(actor);
var graphNode = Editor.Scene.GetActorNode(actor.ID);
if (graphNode != null)
graphNodes.Add(graphNode);
Editor.Scene.MarkSceneEdited(actor.Scene); Editor.Scene.MarkSceneEdited(actor.Scene);
} }
} }
if (graphNodes.Count > 0)
Editor.SceneEditing.Select(graphNodes);
result = DragDropEffect.Move; result = DragDropEffect.Move;
} }