Add context to drag drop for object ref editor.
This commit is contained in:
@@ -8,6 +8,8 @@ using FlaxEditor.GUI;
|
||||
using FlaxEditor.GUI.Drag;
|
||||
using FlaxEditor.SceneGraph;
|
||||
using FlaxEditor.Scripting;
|
||||
using FlaxEditor.Windows;
|
||||
using FlaxEditor.Windows.Assets;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
using FlaxEngine.Utilities;
|
||||
@@ -376,13 +378,13 @@ namespace FlaxEditor.CustomEditors.Editors
|
||||
|
||||
// Ensure to have valid drag helpers (uses lazy init)
|
||||
if (_dragActors == null)
|
||||
_dragActors = new DragActors(x => IsValid(x.Actor));
|
||||
_dragActors = new DragActors(ValidateDragActor);
|
||||
if (_dragActorsWithScript == null)
|
||||
_dragActorsWithScript = new DragActors(ValidateDragActorWithScript);
|
||||
if (_dragAssets == null)
|
||||
_dragAssets = new DragAssets(ValidateDragAsset);
|
||||
if (_dragScripts == null)
|
||||
_dragScripts = new DragScripts(IsValid);
|
||||
_dragScripts = new DragScripts(ValidateDragScript);
|
||||
if (_dragHandlers == null)
|
||||
{
|
||||
_dragHandlers = new DragHandlers
|
||||
@@ -407,6 +409,43 @@ namespace FlaxEditor.CustomEditors.Editors
|
||||
return DragEffect;
|
||||
}
|
||||
|
||||
private bool ValidateDragActor(ActorNode a)
|
||||
{
|
||||
if (!IsValid(a.Actor))
|
||||
return false;
|
||||
|
||||
if (PresenterContext is PrefabWindow prefabWindow)
|
||||
{
|
||||
if (prefabWindow.Tree == a.TreeNode.ParentTree)
|
||||
return true;
|
||||
}
|
||||
else if (PresenterContext is PropertiesWindow || PresenterContext == null)
|
||||
{
|
||||
if (a.ParentScene != null)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool ValidateDragScript(Script script)
|
||||
{
|
||||
if (!IsValid(script))
|
||||
return false;
|
||||
|
||||
if (PresenterContext is PrefabWindow prefabWindow)
|
||||
{
|
||||
var actorNode = prefabWindow.Graph.Root.Find(script.Actor);
|
||||
if (actorNode != null)
|
||||
return true;
|
||||
}
|
||||
else if (PresenterContext is PropertiesWindow || PresenterContext == null)
|
||||
{
|
||||
if (script.Actor.HasScene)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool ValidateDragAsset(AssetItem assetItem)
|
||||
{
|
||||
// Check if can accept assets
|
||||
@@ -425,7 +464,18 @@ namespace FlaxEditor.CustomEditors.Editors
|
||||
|
||||
private bool ValidateDragActorWithScript(ActorNode node)
|
||||
{
|
||||
return node.Actor.Scripts.Any(IsValid);
|
||||
bool isCorrectContext = false;
|
||||
if (PresenterContext is PrefabWindow prefabWindow)
|
||||
{
|
||||
if (prefabWindow.Tree == node.TreeNode.ParentTree)
|
||||
isCorrectContext = true;
|
||||
}
|
||||
else if (PresenterContext is PropertiesWindow || PresenterContext == null)
|
||||
{
|
||||
if (node.ParentScene != null)
|
||||
isCorrectContext = true;
|
||||
}
|
||||
return node.Actor.Scripts.Any(IsValid) && isCorrectContext;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user