diff --git a/Source/Editor/CustomEditors/Editors/ControlReferenceEditor.cs b/Source/Editor/CustomEditors/Editors/ControlReferenceEditor.cs
index d7bbf1502..700accabb 100644
--- a/Source/Editor/CustomEditors/Editors/ControlReferenceEditor.cs
+++ b/Source/Editor/CustomEditors/Editors/ControlReferenceEditor.cs
@@ -4,7 +4,10 @@ using FlaxEditor.CustomEditors;
using FlaxEditor.CustomEditors.Elements;
using FlaxEditor.GUI;
using FlaxEditor.GUI.Drag;
+using FlaxEditor.SceneGraph;
using FlaxEditor.SceneGraph.GUI;
+using FlaxEditor.Windows;
+using FlaxEditor.Windows.Assets;
using FlaxEngine;
using FlaxEngine.GUI;
using FlaxEngine.Utilities;
@@ -31,6 +34,11 @@ public class UIControlRefPickerControl : Control
private DragActors _dragActors;
private DragHandlers _dragHandlers;
+ ///
+ /// The presenter using this control.
+ ///
+ public IPresenterOwner PresenterContext;
+
///
/// Occurs when value gets changed.
///
@@ -126,7 +134,7 @@ public class UIControlRefPickerControl : Control
Value = actor as UIControl;
RootWindow.Focus();
Focus();
- });
+ }, PresenterContext);
}
}
@@ -134,6 +142,24 @@ public class UIControlRefPickerControl : Control
{
return actor == null || actor is UIControl a && a.Control.GetType() == _controlType;
}
+
+ 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;
+ }
///
public override void Draw()
@@ -365,7 +391,7 @@ public class UIControlRefPickerControl : Control
// Ensure to have valid drag helpers (uses lazy init)
if (_dragActors == null)
- _dragActors = new DragActors(x => IsValid(x.Actor));
+ _dragActors = new DragActors(ValidateDragActor);
if (_dragHandlers == null)
{
_dragHandlers = new DragHandlers
@@ -448,6 +474,7 @@ public class ControlReferenceEditor : CustomEditor
Type genType = ValuesTypes[0].GetGenericArguments()[0];
if (typeof(Control).IsAssignableFrom(genType))
{
+ _element.CustomControl.PresenterContext = Presenter.Owner;
_element.CustomControl.ControlType = genType;
}
_element.CustomControl.ValueChanged += () =>
diff --git a/Source/Engine/UI/ControlReference.cs b/Source/Engine/UI/ControlReference.cs
index efcc42362..75b5d57a8 100644
--- a/Source/Engine/UI/ControlReference.cs
+++ b/Source/Engine/UI/ControlReference.cs
@@ -63,7 +63,7 @@ public struct ControlReference : IControlReference where T : Control
return t;
else
{
- Debug.LogWarning("Trying to get Control from ControlReference but UIControl is null, or UIControl.Control is null, or UIControl.Control is not the correct type.");
+ Debug.Write(LogType.Warning, "Trying to get Control from ControlReference but UIControl is null, or UIControl.Control is null, or UIControl.Control is not the correct type.");
return null;
}
}
@@ -84,7 +84,7 @@ public struct ControlReference : IControlReference where T : Control
if (uiControl.Control is T castedControl)
_uiControl = uiControl;
else
- Debug.LogWarning("Trying to set ControlReference but UIControl.Control is null or UIControl.Control is not the correct type.");
+ Debug.Write(LogType.Warning, "Trying to set ControlReference but UIControl.Control is null or UIControl.Control is not the correct type.");
}
///