diff --git a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs
index bf82e19da..ad76ac295 100644
--- a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs
+++ b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs
@@ -254,27 +254,15 @@ namespace FlaxEditor.CustomEditors.Dedicated
/// Small image control added per script group that allows to drag and drop a reference to it. Also used to reorder the scripts.
///
///
- internal class ScriptDragIcon : Image
+ internal class DragImage : Image
{
- private ScriptsEditor _editor;
private bool _isMouseDown;
private Float2 _mouseDownPos;
///
- /// Gets the target script.
+ /// Action called when drag event should start.
///
- public Script Script => (Script)Tag;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The script editor.
- /// The target script.
- public ScriptDragIcon(ScriptsEditor editor, Script script)
- {
- Tag = script;
- _editor = editor;
- }
+ public Action Drag;
///
public override void OnMouseEnter(Float2 location)
@@ -287,11 +275,10 @@ namespace FlaxEditor.CustomEditors.Dedicated
///
public override void OnMouseLeave()
{
- // Check if start drag drop
if (_isMouseDown)
{
- DoDrag();
_isMouseDown = false;
+ Drag(this);
}
base.OnMouseLeave();
@@ -300,11 +287,10 @@ namespace FlaxEditor.CustomEditors.Dedicated
///
public override void OnMouseMove(Float2 location)
{
- // Check if start drag drop
if (_isMouseDown && Float2.Distance(location, _mouseDownPos) > 10.0f)
{
- DoDrag();
_isMouseDown = false;
+ Drag(this);
}
base.OnMouseMove(location);
@@ -315,8 +301,8 @@ namespace FlaxEditor.CustomEditors.Dedicated
{
if (button == MouseButton.Left)
{
- // Clear flag
_isMouseDown = false;
+ return true;
}
return base.OnMouseUp(location, button);
@@ -327,21 +313,13 @@ namespace FlaxEditor.CustomEditors.Dedicated
{
if (button == MouseButton.Left)
{
- // Set flag
_isMouseDown = true;
_mouseDownPos = location;
+ return true;
}
return base.OnMouseDown(location, button);
}
-
- private void DoDrag()
- {
- var script = Script;
- _editor.OnScriptDragChange(true, script);
- DoDragDrop(DragScripts.GetDragData(script));
- _editor.OnScriptDragChange(false, script);
- }
}
internal class ScriptArrangeBar : Control
@@ -639,7 +617,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
_scriptToggles[i] = scriptToggle;
// Add drag button to the group
- var scriptDrag = new ScriptDragIcon(this, script)
+ var scriptDrag = new DragImage
{
TooltipText = "Script reference",
AutoFocus = true,
@@ -650,6 +628,13 @@ namespace FlaxEditor.CustomEditors.Dedicated
Margin = new Margin(1),
Brush = new SpriteBrush(Editor.Instance.Icons.DragBar12),
Tag = script,
+ Drag = img =>
+ {
+ var s = (Script)img.Tag;
+ OnScriptDragChange(true, s);
+ img.DoDragDrop(DragScripts.GetDragData(s));
+ OnScriptDragChange(false, s);
+ }
};
// Add settings button to the group
diff --git a/Source/Editor/GUI/Drag/DragScripts.cs b/Source/Editor/GUI/Drag/DragScripts.cs
index e72d28479..875875ef3 100644
--- a/Source/Editor/GUI/Drag/DragScripts.cs
+++ b/Source/Editor/GUI/Drag/DragScripts.cs
@@ -58,7 +58,6 @@ namespace FlaxEditor.GUI.Drag
{
if (item == null)
throw new ArgumentNullException();
-
return new DragDataText(DragPrefix + item.ID.ToString("N"));
}
@@ -71,11 +70,9 @@ namespace FlaxEditor.GUI.Drag
{
if (items == null)
throw new ArgumentNullException();
-
string text = DragPrefix;
foreach (var item in items)
text += item.ID.ToString("N") + '\n';
-
return new DragDataText(text);
}
@@ -83,9 +80,7 @@ namespace FlaxEditor.GUI.Drag
/// Tries to parse the drag data.
///
/// The data.
- ///
- /// Gathered objects or empty IEnumerable if cannot get any valid.
- ///
+ /// Gathered objects or empty IEnumerable if cannot get any valid.
public override IEnumerable