summaryrefslogtreecommitdiff
path: root/Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/DragNode.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/DragNode.cs')
-rw-r--r--Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/DragNode.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/DragNode.cs b/Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/DragNode.cs
new file mode 100644
index 00000000..9e4d89d0
--- /dev/null
+++ b/Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/DragNode.cs
@@ -0,0 +1,42 @@
+
+using UnityEngine;
+
+namespace UNEB
+{
+ public class DragNode : MultiStageAction
+ {
+ private Node _draggingNode;
+
+ private Vector2 _startDragPos, _endDragPos;
+
+ public const float dragSpeed = 1f;
+
+ public override void Undo()
+ {
+ _draggingNode.bodyRect.position = _startDragPos;
+ }
+
+ public override void Redo()
+ {
+ _draggingNode.bodyRect.position = _endDragPos;
+ }
+
+ public override void Do()
+ {
+ NodeEditor editor = manager.window.editor;
+ _draggingNode.bodyRect.position += Event.current.delta * editor.ZoomScale * dragSpeed;
+ }
+
+ public override void OnActionStart()
+ {
+ _draggingNode = manager.window.state.selectedNode;
+ _startDragPos = _draggingNode.bodyRect.position;
+ }
+
+ public override bool OnActionEnd()
+ {
+ _endDragPos = _draggingNode.bodyRect.position;
+ return true;
+ }
+ }
+} \ No newline at end of file