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:
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

@ -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{
}
}

@ -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<Comment> _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<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(){
@ -440,6 +453,16 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
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();
}
@ -564,12 +587,21 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
private void SaveEditorModels(){
var placemats = placematContainer.Placemats.ToList();
var comments = this.Query<CommentView>().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<Comment> Comments{
get => _comments;
set => _comments = value;
}
private void SaveBlackboard(){
@ -781,6 +813,8 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
}
public class DataChangedEventArgs<T>{
public DataChangedEventArgs(T data){
NewData = data;

Loading…
Cancel
Save