From 58604d5ccab9953507d44ec039ea8d12e94d8f3e Mon Sep 17 00:00:00 2001 From: godzzz Date: Sun, 12 May 2024 10:51:31 +0400 Subject: [PATCH] [v0.0.2] Comment node; Cleaning --- Editor/View/CodeGraphView.cs | 60 +++++++++++++++---------------- Runtime/Nodes/CommentNode.cs | 14 ++++++++ Runtime/Nodes/CommentNode.cs.meta | 3 ++ Runtime/Nodes/StartNode.cs | 2 ++ package.json | 2 +- 5 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 Runtime/Nodes/CommentNode.cs create mode 100644 Runtime/Nodes/CommentNode.cs.meta diff --git a/Editor/View/CodeGraphView.cs b/Editor/View/CodeGraphView.cs index fb824dd..55b8fab 100644 --- a/Editor/View/CodeGraphView.cs +++ b/Editor/View/CodeGraphView.cs @@ -87,6 +87,16 @@ public void Create(CodeGraphNode node) Bind(); } + internal void RemoveNode(CodeGraphEditorNode editorNode) + { + Undo.RecordObject(_serializedObject.targetObject, "Removed Node"); + + _nodes.Remove(editorNode); + _tree.Nodes.Remove(editorNode.Node); + _nodeLookup.Remove(editorNode.Node.Guid); + _serializedObject.Update(); + } + private void PopulateNodes(IEnumerable graphNodes) { foreach (var node in graphNodes) @@ -95,6 +105,26 @@ private void PopulateNodes(IEnumerable graphNodes) } } + internal void RemoveConnection(Edge edge) + { + if (_edgeLookup.Remove(edge, out var connection)) + { + _tree.Connections.Remove(connection); + } + } + + internal void CreateEdge(Edge edge) + { + var inputNode = (CodeGraphEditorNode) edge.input.node; + var outputNode = (CodeGraphEditorNode) edge.output.node; + + var inputIndex = inputNode.Ports.IndexOf(edge.input); + var outputIndex = outputNode.Ports.IndexOf(edge.output); + + var connection = new CodeGraphConnection(inputNode.Id, inputIndex, outputNode.Id, outputIndex); + _tree.Connections.Add(connection); + } + private void PopulateConnections(IEnumerable connections) { foreach (var connection in connections) @@ -133,24 +163,6 @@ private void AddNode(CodeGraphNode node) AddElement(editorNode); } - internal void RemoveNode(CodeGraphEditorNode editorNode) - { - Undo.RecordObject(_serializedObject.targetObject, "Removed Node"); - - _nodes.Remove(editorNode); - _tree.Nodes.Remove(editorNode.Node); - _nodeLookup.Remove(editorNode.Node.Guid); - _serializedObject.Update(); - } - - internal void RemoveConnection(Edge edge) - { - if (_edgeLookup.Remove(edge, out var connection)) - { - _tree.Connections.Remove(connection); - } - } - private void AddGridBackground() { var grid = new GridBackground(); @@ -167,18 +179,6 @@ private void AddStyles() styleSheets.Add(styleSheet); } - internal void CreateEdge(Edge edge) - { - var inputNode = (CodeGraphEditorNode) edge.input.node; - var outputNode = (CodeGraphEditorNode) edge.output.node; - - var inputIndex = inputNode.Ports.IndexOf(edge.input); - var outputIndex = outputNode.Ports.IndexOf(edge.output); - - var connection = new CodeGraphConnection(inputNode.Id, inputIndex, outputNode.Id, outputIndex); - _tree.Connections.Add(connection); - } - private void Bind() { _serializedObject.Update(); diff --git a/Runtime/Nodes/CommentNode.cs b/Runtime/Nodes/CommentNode.cs new file mode 100644 index 0000000..e376912 --- /dev/null +++ b/Runtime/Nodes/CommentNode.cs @@ -0,0 +1,14 @@ +using System; +using Depra.CodeGraph.Attributes; +using UnityEngine; + +namespace Depra.CodeGraph +{ + [Serializable] + [NodeTitle("Comment")] + [NodeMenuPath("Comment")] + internal sealed class CommentNode : CodeGraphNode + { + [SerializeField] private string _text; + } +} \ No newline at end of file diff --git a/Runtime/Nodes/CommentNode.cs.meta b/Runtime/Nodes/CommentNode.cs.meta new file mode 100644 index 0000000..377532d --- /dev/null +++ b/Runtime/Nodes/CommentNode.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ed3342807d9e4aaba9129de047dd7f05 +timeCreated: 1714564277 \ No newline at end of file diff --git a/Runtime/Nodes/StartNode.cs b/Runtime/Nodes/StartNode.cs index 9997257..b796e6c 100644 --- a/Runtime/Nodes/StartNode.cs +++ b/Runtime/Nodes/StartNode.cs @@ -1,10 +1,12 @@ // SPDX-License-Identifier: Apache-2.0 // © 2024 Nikolay Melnikov +using System; using Depra.CodeGraph.Attributes; namespace Depra.CodeGraph { + [Serializable] [HasFlowOutput] [NodeTitle("Start")] [NodeMenuPath("Process/Start")] diff --git a/package.json b/package.json index 78bf990..e0708f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.depra.code-graph", - "version": "0.0.1", + "version": "0.0.2", "displayName": "Depra.CodeGraph", "description": "", "unity": "2022.3",