From 49b25e755b70ec412feaaf0b898d6f7e09d2bea6 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 28 Jun 2022 09:40:37 +0800 Subject: +node example --- .../Assets/UNEB/Editor/Actions/DragNode.cs | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/DragNode.cs (limited to 'Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/DragNode.cs') 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 -- cgit v1.1-26-g67d0