From b8494278cf0e8a88a45af86337eaf6e939defaef Mon Sep 17 00:00:00 2001 From: taoria <445625470@qq.com> Date: Wed, 10 Aug 2022 10:28:21 +0800 Subject: [PATCH] feature:Add a comment block for nodes --- TNode/Samples/New HelloGraph.asset | 46 ++++++++++++------- TNode/TNodeCore/Runtime/Models/NodeData.cs | 3 ++ .../Editor/NodeGraphView/DataGraphView.cs | 36 ++++++++++++++- 3 files changed, 68 insertions(+), 17 deletions(-) diff --git a/TNode/Samples/New HelloGraph.asset b/TNode/Samples/New HelloGraph.asset index 3d9051f..f699d86 100644 --- a/TNode/Samples/New HelloGraph.asset +++ b/TNode/Samples/New HelloGraph.asset @@ -32,9 +32,10 @@ MonoBehaviour: blackboardData: id: 3 sceneReference: - editorModels: [] + editorModels: + - id: 4 graphViewModel: - id: 4 + id: 5 references: version: 1 00000000: @@ -53,33 +54,33 @@ MonoBehaviour: blackDragData: V3S.0 isListElement: 1 00000001: - type: {class: AddNode, ns: Samples, asm: Assembly-CSharp} + type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly} data: positionInView: serializedVersion: 2 - x: 454 - y: 280 + x: 225 + y: 382 width: 0 height: 0 - id: 3e72627f-af97-4056-b89c-04d4f2f127f5 - nodeName: AddNode + id: 1a4fd419-5584-4d43-a8c3-bebcad63a337 + nodeName: entryPoint: 0 isTest: 0 + blackDragData: V2S.0 + isListElement: 1 00000002: - type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly} + type: {class: AddNode, ns: Samples, asm: Assembly-CSharp} data: positionInView: serializedVersion: 2 - x: 225 - y: 382 + x: 488 + y: 280 width: 0 height: 0 - id: 1a4fd419-5584-4d43-a8c3-bebcad63a337 - nodeName: + id: 3e72627f-af97-4056-b89c-04d4f2f127f5 + nodeName: AddNode entryPoint: 0 isTest: 0 - blackDragData: V2S.0 - isListElement: 1 00000003: type: {class: HelloBlackboard, ns: TNode.Samples, asm: Assembly-CSharp} data: @@ -89,6 +90,7 @@ MonoBehaviour: y: 0 width: 0 height: 0 + id: HelloString: HelloGameObject: {fileID: 0} V3S: @@ -96,6 +98,17 @@ MonoBehaviour: V2S: - {x: 0, y: 0} 00000004: + type: {class: Comment, ns: TNode.TNodeCore.Editor.Models, asm: NewAssembly} + data: + positionInView: + serializedVersion: 2 + x: 0 + y: 0 + width: 0 + height: 0 + id: + CommentText: + 00000005: type: {class: GraphViewModel, ns: TNode.TNodeCore.Editor.Models, asm: NewAssembly} data: positionInView: @@ -104,6 +117,7 @@ MonoBehaviour: y: 0 width: 0 height: 0 - persistScale: 0.57175326 - persistOffset: {x: 343, y: 15} + id: + persistScale: 1 + persistOffset: {x: 114, y: -155} isBlackboardOn: 1 diff --git a/TNode/TNodeCore/Runtime/Models/NodeData.cs b/TNode/TNodeCore/Runtime/Models/NodeData.cs index f286180..b59c9e8 100644 --- a/TNode/TNodeCore/Runtime/Models/NodeData.cs +++ b/TNode/TNodeCore/Runtime/Models/NodeData.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using TNodeCore.Runtime.Attributes; using UnityEngine; @@ -39,4 +40,6 @@ namespace TNodeCore.Runtime.Models{ } + + } \ No newline at end of file diff --git a/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs b/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs index fcf6b38..d374c97 100644 --- a/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs +++ b/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; using TNode.TNodeCore.Editor.Blackboard; +using TNode.TNodeCore.Editor.CommentView; using TNode.TNodeCore.Editor.EditorPersistence; using TNode.TNodeCore.Editor.Models; using TNode.TNodeGraphViewImpl.Editor.Cache; @@ -23,6 +24,7 @@ using TNodeCore.Runtime.RuntimeCache; using UnityEditor; using UnityEditor.Experimental.GraphView; +using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; using BlackboardField = TNode.TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardField; @@ -43,6 +45,8 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ private IBlackboardView _blackboard; private bool _loaded; private GraphViewModel _graphViewModel; + private List _comments; + public T Data{ get{ return _data; } set{ @@ -224,7 +228,16 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ } private void BuildCommentForSelected(){ - throw new NotImplementedException(); + var selection = this.selection.OfType().ToList(); + foreach (var baseNodeView in selection){ + var comment = new CommentView(); + comment.Bind(new Comment(){ + + }); + ((GraphElement)baseNodeView).Add(comment); + comment.Data.CommentedModel = baseNodeView.GetNodeData(); + this._data.EditorModels.Add(comment.Data); + } } private void DeleteSelected(){ @@ -440,6 +453,16 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ res.PlacematModel = placemat; } + + var comments = _data.EditorModels.OfType(); + foreach (var comment in comments){ + var res = new CommentView(); + res.Bind(comment); + var node = _nodeDict[comment.CommentedModel.id]; + if (node != null){ + node.Add(res); + } + } _nodeDict.Clear(); } @@ -564,12 +587,21 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ private void SaveEditorModels(){ var placemats = placematContainer.Placemats.ToList(); + var comments = this.Query().ToList(); Debug.Log(placemats.Count); foreach (var placemat in placemats){ if (placemat is PlacematView placematView){ _data.EditorModels.Add(placematView.PlacematModel); } } + foreach (var commentView in comments){ + _data.EditorModels.Add(commentView.Data); + } + } + + public List Comments{ + get => _comments; + set => _comments = value; } private void SaveBlackboard(){ @@ -781,6 +813,8 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ } + + public class DataChangedEventArgs{ public DataChangedEventArgs(T data){ NewData = data;