diff --git a/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs b/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs index b4143140d..1dc624525 100644 --- a/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs +++ b/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs @@ -9,6 +9,8 @@ using FlaxEditor.GUI.Drag; using FlaxEditor.SceneGraph; using FlaxEditor.SceneGraph.GUI; using FlaxEditor.Scripting; +using FlaxEditor.Windows; +using FlaxEditor.Windows.Assets; using FlaxEngine; using FlaxEngine.GUI; using FlaxEngine.Utilities; @@ -40,6 +42,11 @@ namespace FlaxEditor.CustomEditors.Editors private DragScripts _dragScripts; private DragHandlers _dragHandlers; + /// + /// The presenter using this control. + /// + public IPresenterOwner PresenterContext; + /// /// Gets or sets the allowed objects type (given type and all sub classes). Must be type of any subclass. /// @@ -159,7 +166,7 @@ namespace FlaxEditor.CustomEditors.Editors Value = actor; RootWindow.Focus(); Focus(); - }); + }, PresenterContext); } else { @@ -168,7 +175,7 @@ namespace FlaxEditor.CustomEditors.Editors Value = script; RootWindow.Focus(); Focus(); - }); + }, PresenterContext); } } @@ -427,13 +434,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 @@ -458,6 +465,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 @@ -476,7 +520,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; } /// @@ -548,6 +603,7 @@ namespace FlaxEditor.CustomEditors.Editors if (!HasDifferentTypes) { _element = layout.Custom(); + _element.CustomControl.PresenterContext = Presenter.Owner; _element.CustomControl.Type = Values.Type.Type != typeof(object) || Values[0] == null ? Values.Type : TypeUtils.GetObjectType(Values[0]); _element.CustomControl.ValueChanged += () => SetValue(_element.CustomControl.Value); } diff --git a/Source/Editor/GUI/Popups/ActorSearchPopup.cs b/Source/Editor/GUI/Popups/ActorSearchPopup.cs index 2c327b685..7be17db98 100644 --- a/Source/Editor/GUI/Popups/ActorSearchPopup.cs +++ b/Source/Editor/GUI/Popups/ActorSearchPopup.cs @@ -1,6 +1,8 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. using System; +using FlaxEditor.Windows; +using FlaxEditor.Windows.Assets; using FlaxEngine; using FlaxEngine.GUI; @@ -55,18 +57,26 @@ namespace FlaxEditor.GUI private IsValidDelegate _isValid; private Action _selected; - private ActorSearchPopup(IsValidDelegate isValid, Action selected) + private ActorSearchPopup(IsValidDelegate isValid, Action selected, CustomEditors.IPresenterOwner context) { _isValid = isValid; _selected = selected; ItemClicked += OnItemClicked; - // TODO: use async thread to search scenes - for (int i = 0; i < Level.ScenesCount; i++) + if (context is PropertiesWindow propertiesWindow || context == null) { - Find(Level.GetScene(i)); + // TODO: use async thread to search scenes + for (int i = 0; i < Level.ScenesCount; i++) + { + Find(Level.GetScene(i)); + } } + else if (context is PrefabWindow prefabWindow) + { + Find(prefabWindow.Graph.MainActor); + } + SortItems(); } @@ -98,10 +108,11 @@ namespace FlaxEditor.GUI /// The show target location. /// Event called to check if a given actor item is valid to be used. /// Event called on actor item pick. + /// The presenter owner context (i.e. PrefabWindow, PropertiesWindow). /// The dialog. - public static ActorSearchPopup Show(Control showTarget, Float2 showTargetLocation, IsValidDelegate isValid, Action selected) + public static ActorSearchPopup Show(Control showTarget, Float2 showTargetLocation, IsValidDelegate isValid, Action selected, CustomEditors.IPresenterOwner context) { - var popup = new ActorSearchPopup(isValid, selected); + var popup = new ActorSearchPopup(isValid, selected, context); popup.Show(showTarget, showTargetLocation); return popup; } diff --git a/Source/Editor/GUI/Popups/ScriptSearchPopup.cs b/Source/Editor/GUI/Popups/ScriptSearchPopup.cs index 93c860275..a6414bb86 100644 --- a/Source/Editor/GUI/Popups/ScriptSearchPopup.cs +++ b/Source/Editor/GUI/Popups/ScriptSearchPopup.cs @@ -1,6 +1,8 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. using System; +using FlaxEditor.Windows; +using FlaxEditor.Windows.Assets; using FlaxEngine; using FlaxEngine.GUI; using FlaxEngine.Utilities; @@ -66,18 +68,26 @@ namespace FlaxEditor.GUI private IsValidDelegate _isValid; private Action