feature:Add a comment block for nodes

main
taoria 3 years ago
parent 07384a387b
commit b8494278cf
  1. 46
      TNode/Samples/New HelloGraph.asset
  2. 3
      TNode/TNodeCore/Runtime/Models/NodeData.cs
  3. 36
      TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs

@ -32,9 +32,10 @@ MonoBehaviour:
blackboardData: blackboardData:
id: 3 id: 3
sceneReference: sceneReference:
editorModels: [] editorModels:
- id: 4
graphViewModel: graphViewModel:
id: 4 id: 5
references: references:
version: 1 version: 1
00000000: 00000000:
@ -53,33 +54,33 @@ MonoBehaviour:
blackDragData: V3S.0 blackDragData: V3S.0
isListElement: 1 isListElement: 1
00000001: 00000001:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp} type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly}
data: data:
positionInView: positionInView:
serializedVersion: 2 serializedVersion: 2
x: 454 x: 225
y: 280 y: 382
width: 0 width: 0
height: 0 height: 0
id: 3e72627f-af97-4056-b89c-04d4f2f127f5 id: 1a4fd419-5584-4d43-a8c3-bebcad63a337
nodeName: AddNode nodeName:
entryPoint: 0 entryPoint: 0
isTest: 0 isTest: 0
blackDragData: V2S.0
isListElement: 1
00000002: 00000002:
type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly} type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data: data:
positionInView: positionInView:
serializedVersion: 2 serializedVersion: 2
x: 225 x: 488
y: 382 y: 280
width: 0 width: 0
height: 0 height: 0
id: 1a4fd419-5584-4d43-a8c3-bebcad63a337 id: 3e72627f-af97-4056-b89c-04d4f2f127f5
nodeName: nodeName: AddNode
entryPoint: 0 entryPoint: 0
isTest: 0 isTest: 0
blackDragData: V2S.0
isListElement: 1
00000003: 00000003:
type: {class: HelloBlackboard, ns: TNode.Samples, asm: Assembly-CSharp} type: {class: HelloBlackboard, ns: TNode.Samples, asm: Assembly-CSharp}
data: data:
@ -89,6 +90,7 @@ MonoBehaviour:
y: 0 y: 0
width: 0 width: 0
height: 0 height: 0
id:
HelloString: HelloString:
HelloGameObject: {fileID: 0} HelloGameObject: {fileID: 0}
V3S: V3S:
@ -96,6 +98,17 @@ MonoBehaviour:
V2S: V2S:
- {x: 0, y: 0} - {x: 0, y: 0}
00000004: 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} type: {class: GraphViewModel, ns: TNode.TNodeCore.Editor.Models, asm: NewAssembly}
data: data:
positionInView: positionInView:
@ -104,6 +117,7 @@ MonoBehaviour:
y: 0 y: 0
width: 0 width: 0
height: 0 height: 0
persistScale: 0.57175326 id:
persistOffset: {x: 343, y: 15} persistScale: 1
persistOffset: {x: 114, y: -155}
isBlackboardOn: 1 isBlackboardOn: 1

@ -1,5 +1,6 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using TNodeCore.Runtime.Attributes; using TNodeCore.Runtime.Attributes;
using UnityEngine; using UnityEngine;
@ -39,4 +40,6 @@ namespace TNodeCore.Runtime.Models{
} }
} }

@ -4,6 +4,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using TNode.TNodeCore.Editor.Blackboard; using TNode.TNodeCore.Editor.Blackboard;
using TNode.TNodeCore.Editor.CommentView;
using TNode.TNodeCore.Editor.EditorPersistence; using TNode.TNodeCore.Editor.EditorPersistence;
using TNode.TNodeCore.Editor.Models; using TNode.TNodeCore.Editor.Models;
using TNode.TNodeGraphViewImpl.Editor.Cache; using TNode.TNodeGraphViewImpl.Editor.Cache;
@ -23,6 +24,7 @@ using TNodeCore.Runtime.RuntimeCache;
using UnityEditor; using UnityEditor;
using UnityEditor.Experimental.GraphView; using UnityEditor.Experimental.GraphView;
using UnityEditor.UIElements;
using UnityEngine; using UnityEngine;
using UnityEngine.UIElements; using UnityEngine.UIElements;
using BlackboardField = TNode.TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardField; using BlackboardField = TNode.TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardField;
@ -43,6 +45,8 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
private IBlackboardView _blackboard; private IBlackboardView _blackboard;
private bool _loaded; private bool _loaded;
private GraphViewModel _graphViewModel; private GraphViewModel _graphViewModel;
private List<Comment> _comments;
public T Data{ public T Data{
get{ return _data; } get{ return _data; }
set{ set{
@ -224,7 +228,16 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
} }
private void BuildCommentForSelected(){ private void BuildCommentForSelected(){
throw new NotImplementedException(); var selection = this.selection.OfType<IBaseNodeView>().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(){ private void DeleteSelected(){
@ -440,6 +453,16 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
res.PlacematModel = placemat; res.PlacematModel = placemat;
} }
var comments = _data.EditorModels.OfType<Comment>();
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(); _nodeDict.Clear();
} }
@ -564,12 +587,21 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
private void SaveEditorModels(){ private void SaveEditorModels(){
var placemats = placematContainer.Placemats.ToList(); var placemats = placematContainer.Placemats.ToList();
var comments = this.Query<CommentView>().ToList();
Debug.Log(placemats.Count); Debug.Log(placemats.Count);
foreach (var placemat in placemats){ foreach (var placemat in placemats){
if (placemat is PlacematView placematView){ if (placemat is PlacematView placematView){
_data.EditorModels.Add(placematView.PlacematModel); _data.EditorModels.Add(placematView.PlacematModel);
} }
} }
foreach (var commentView in comments){
_data.EditorModels.Add(commentView.Data);
}
}
public List<Comment> Comments{
get => _comments;
set => _comments = value;
} }
private void SaveBlackboard(){ private void SaveBlackboard(){
@ -781,6 +813,8 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
} }
public class DataChangedEventArgs<T>{ public class DataChangedEventArgs<T>{
public DataChangedEventArgs(T data){ public DataChangedEventArgs(T data){
NewData = data; NewData = data;

Loading…
Cancel
Save