summaryrefslogtreecommitdiff
path: root/Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/DragNode.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2022-06-28 09:40:37 +0800
committerchai <chaifix@163.com>2022-06-28 09:40:37 +0800
commit49b25e755b70ec412feaaf0b898d6f7e09d2bea6 (patch)
tree3c5f4260f30d1c2d7196db93153700d7ddec3157 /Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/DragNode.cs
parentc92269331692feca2c276649f6c4ee8911f1f859 (diff)
+node example
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