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/CreateNodeAction.cs | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/CreateNodeAction.cs (limited to 'Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/CreateNodeAction.cs') diff --git a/Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/CreateNodeAction.cs b/Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/CreateNodeAction.cs new file mode 100644 index 00000000..522fa0cb --- /dev/null +++ b/Other/NodeEditorExamples/Assets/UNEB/Editor/Actions/CreateNodeAction.cs @@ -0,0 +1,55 @@ + +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace UNEB +{ + public class CreateNodeAction : UndoableAction + { + private NodeGraph _graph; + private Node _nodeCreated; + + // The node referenced can only be destroyed if the + // create action has been undone. + private bool _bCanDeleteNode = false; + + public override bool Init() + { + System.Type t = manager.window.state.typeToCreate; + return t != null && typeof(Node).IsAssignableFrom(t); + } + + public override void Do() + { + _graph = manager.window.graph; + + var state = manager.window.state; + + _nodeCreated = SaveManager.CreateNode(state.typeToCreate, _graph); + _nodeCreated.bodyRect.position = manager.window.state.lastClickedPosition; + + // Done with this type creation. + state.typeToCreate = null; + } + + public override void Undo() + { + _graph.Remove(_nodeCreated); + _bCanDeleteNode = true; + } + + public override void Redo() + { + _graph.Add(_nodeCreated); + _bCanDeleteNode = false; + } + + public override void OnDestroy() + { + if (_bCanDeleteNode && _nodeCreated) { + ScriptableObject.DestroyImmediate(_nodeCreated, true); + } + } + } +} \ No newline at end of file -- cgit v1.1-26-g67d0