Merge pull request #41 from taoria/work-in-progress

Work in progress
main
taoria 3 years ago committed by GitHub
commit 5aca5d7f43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      README.md
  2. 157
      TNode/Samples/New HelloGraph.asset
  3. 2
      TNode/Samples/New HelloGraph.asset.meta
  4. 3
      TNode/TNodeCore/Editor/Binding.meta
  5. 7
      TNode/TNodeCore/Editor/Binding/IModelBinding.cs
  6. 3
      TNode/TNodeCore/Editor/Binding/IModelBinding.cs.meta
  7. 3
      TNode/TNodeCore/Editor/CommentView.meta
  8. 49
      TNode/TNodeCore/Editor/CommentView/CommentView.cs
  9. 3
      TNode/TNodeCore/Editor/CommentView/CommentView.cs.meta
  10. 10
      TNode/TNodeCore/Editor/Models/Comment.cs
  11. 3
      TNode/TNodeCore/Editor/Models/Comment.cs.meta
  12. 6
      TNode/TNodeCore/Editor/Resources/CommentView.uss
  13. 3
      TNode/TNodeCore/Editor/Resources/CommentView.uss.meta
  14. 1
      TNode/TNodeCore/Editor/Tools/GraphEditorCreator/GraphEditorCreator.cs
  15. 10
      TNode/TNodeCore/Runtime/Models/Model.cs
  16. 6
      TNode/TNodeCore/Runtime/Models/NodeData.cs
  17. 5
      TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs
  18. 56
      TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs

@ -14,11 +14,10 @@ the main goal of the repo is to make graph creation easier and more intuitive.
* Scene object nodes hold scene objects like blackboard
# Some to-dos
* Port connectivity of two types have implicit conversion
* Node placemat
* Vertical node
* A universal merger handle multiple input
* Support static graph data traversal
* Support graph data traversal like FSM
* Conditional edge
# Install & Usage
Right now this lib is still under development.

@ -16,128 +16,72 @@ MonoBehaviour:
- id: 0
- id: 1
- id: 2
- id: 3
- id: 4
- id: 5
- id: 6
- id: 7
nodeLinks: []
nodeLinks:
- inPort:
portEntryName: A
nodeDataId: 3e72627f-af97-4056-b89c-04d4f2f127f5
outPort:
portEntryName: Value
nodeDataId: 4414d05b-da96-465e-a593-2e3dcfceaf23
- inPort:
portEntryName: B
nodeDataId: 3e72627f-af97-4056-b89c-04d4f2f127f5
outPort:
portEntryName: Value
nodeDataId: 1a4fd419-5584-4d43-a8c3-bebcad63a337
blackboardData:
id: 8
id: 3
sceneReference:
editorModels:
- id: 9
graphViewData:
id: 10
- id: 4
graphViewModel:
id: 5
references:
version: 1
00000000:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly}
data:
positionInView:
serializedVersion: 2
x: 1944
y: 205
x: 519
y: 361
width: 0
height: 0
id: 74136d91-e634-401b-8c99-3c2bb351cab2
nodeName: AddNode
id: 4414d05b-da96-465e-a593-2e3dcfceaf23
nodeName:
entryPoint: 0
isTest: 0
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: 2045
y: 205
x: 519
y: 443
width: 0
height: 0
id: 8bee0814-52ef-4068-bffb-58a786d73ec2
nodeName: AddNode
id: 1a4fd419-5584-4d43-a8c3-bebcad63a337
nodeName:
entryPoint: 0
isTest: 0
blackDragData: V2S.0
isListElement: 1
00000002:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data:
positionInView:
serializedVersion: 2
x: 2146
y: 205
x: 630
y: 361
width: 0
height: 0
id: 819d1689-d64d-41ca-a9ac-0e00d25806c0
id: 3e72627f-af97-4056-b89c-04d4f2f127f5
nodeName: AddNode
entryPoint: 0
isTest: 0
00000003:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data:
positionInView:
serializedVersion: 2
x: 2247
y: 205
width: 0
height: 0
id: b8495e41-8ec2-4015-8784-7a99c1003c6b
nodeName: AddNode
entryPoint: 0
isTest: 0
00000004:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data:
positionInView:
serializedVersion: 2
x: 2014
y: 340
width: 0
height: 0
id: 3f27f6fe-b2db-41f2-9b3f-5e5fc468e536
nodeName: AddNode
entryPoint: 0
isTest: 0
00000005:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data:
positionInView:
serializedVersion: 2
x: 2130
y: 340
width: 0
height: 0
id: 6500c6c2-3551-4930-8338-afd02a49105b
nodeName: AddNode
entryPoint: 0
isTest: 0
00000006:
type: {class: AddNode, ns: Samples, asm: Assembly-CSharp}
data:
positionInView:
serializedVersion: 2
x: 2247
y: 340
width: 0
height: 0
id: 002de40a-5ef5-4e99-8373-2628d189d6c9
nodeName: AddNode
entryPoint: 0
isTest: 0
00000007:
type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly}
data:
positionInView:
serializedVersion: 2
x: 1944.9998
y: 475.8858
width: 0
height: 0
id: 2f9adf6b-b40b-4fbd-9bd6-0d1ebb10992f
nodeName:
entryPoint: 0
isTest: 0
blackDragData: HelloGameObject
isListElement: 0
00000008:
type: {class: HelloBlackboard, ns: TNode.Samples, asm: Assembly-CSharp}
data:
positionInView:
@ -146,26 +90,28 @@ MonoBehaviour:
y: 0
width: 0
height: 0
HelloString: hello
HelloGameObject: {fileID: 3675195758153116951, guid: 35a9f7ccd0ed7d744b85580016a0aab5, type: 3}
id:
HelloString:
HelloGameObject: {fileID: 0}
V3S:
- {x: 0, y: 0, z: 0}
V2S:
- {x: 0, y: 0}
00000009:
type: {class: PlacematData, ns: TNodeCore.Editor.Models, asm: NewAssembly}
00000004:
type: {class: Comment, ns: TNode.TNodeCore.Editor.Models, asm: NewAssembly}
data:
positionInView:
serializedVersion: 2
x: 1903.9056
y: 75.76817
width: 500
height: 500
hostModels: []
zOrder: 0
title: Title
0000000A:
type: {class: GraphViewData, ns: TNode.TNodeCore.Editor.Models, asm: NewAssembly}
x: 0
y: 0
width: 0
height: 0
id:
CommentedModel:
id: 2
CommentText:
00000005:
type: {class: GraphViewModel, ns: TNode.TNodeCore.Editor.Models, asm: NewAssembly}
data:
positionInView:
serializedVersion: 2
@ -173,6 +119,7 @@ MonoBehaviour:
y: 0
width: 0
height: 0
persistScale: 0.8695652
persistOffset: {x: -878, y: -29}
id:
persistScale: 1
persistOffset: {x: -302, y: -93}
isBlackboardOn: 1

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 490933fc590be444780d73cd9f777ed4
guid: f55ebad0b05015a4f873ac78896d95d3
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 919363d9cb9c43a1a14fb12abc76a53b
timeCreated: 1660042822

@ -0,0 +1,7 @@
namespace TNode.TNodeCore.Editor.Binding{
public interface IModelBinding<T>{
public T Data{ get; }
public void Bind(T data);
public void OnChange();
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c25080540d844798a8c71e2b8feadf93
timeCreated: 1660042832

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a5166d364fc64b82bce9580b4411c83e
timeCreated: 1660042541

@ -0,0 +1,49 @@
using System;
using TNode.TNodeCore.Editor.Binding;
using TNode.TNodeCore.Editor.Models;
using TNodeCore.Editor.NodeGraphView;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
namespace TNode.TNodeCore.Editor.CommentView{
public class CommentView:GraphElement,IModelBinding<Comment>{
public Comment Data => _data;
private Comment _data;
public void Bind(Comment data){
_data = data;
OnChange();
}
public CommentView(){
var txtField = new TextField();
var btn = new Button(() => {
var graphElement = (Node) this.GetFirstOfType<Node>();
graphElement.Remove(this);
});
btn.text = "-";
this.Add(btn);
this.Add(txtField);
txtField.RegisterValueChangedCallback(evt => {
if (_data != null){
_data.CommentText = evt.newValue;
}
});
capabilities |= Capabilities.Collapsible | Capabilities.Deletable|Capabilities.Selectable;
styleSheets.Add(Resources.Load<StyleSheet>("CommentView"));
}
private void ClickComment(){
}
public void OnChange(){
var str = this._data.CommentText;
this.Q<TextField>().value = str;
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e0f3542295fd4138967335f3ce44b5f2
timeCreated: 1660042529

@ -0,0 +1,10 @@
using TNodeCore.Runtime.Models;
using UnityEngine;
namespace TNode.TNodeCore.Editor.Models{
public class Comment:EditorModel{
[SerializeReference]
public Model CommentedModel;
public string CommentText;
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a7a79224e74245789ccaa833d12b833d
timeCreated: 1660041914

@ -0,0 +1,6 @@
TextField{
min-width: 400px;
}
{
flex-direction: row;
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 03185df2d8c7459fb302d053876477b6
timeCreated: 1660101516

@ -146,7 +146,6 @@ namespace TNodeCore.Editor.Tools.GraphEditorCreator{
//Create an NodeAttribute Editor Data Instance for the new graph editor
var graphEditorData = ScriptableObject.CreateInstance<GraphEditorData>();
graphEditorData.name = editorName;
VisualTreeAsset defaultEditorTree = Resources.Load<VisualTreeAsset>("GraphEditor");
EditorUtility.SetDirty(graphEditorData);

@ -10,10 +10,18 @@ namespace TNodeCore.Runtime.Models{
[HideInBlackboard]
public Rect positionInView;
#endif
[DisableOnInspector]
[HideInBlackboard]
public string id;
[NonSerialized]
private int _fastAccessId=0;
public object Clone(){
var memberwiseClone = this.MemberwiseClone();
return memberwiseClone;
}
/// <summary>
/// Record and map the node by a string is cost.converted it to an integer to speed the process.
/// </summary>
public int FastAccessId => _fastAccessId==0?_fastAccessId=GetHashCode():_fastAccessId;
}
}

@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TNodeCore.Runtime.Attributes;
using UnityEngine;
@ -18,8 +19,7 @@ namespace TNodeCore.Runtime.Models{
//Object Registration
}
[DisableOnInspector]
public string id;
public string nodeName;
public bool entryPoint;
@ -40,4 +40,6 @@ namespace TNodeCore.Runtime.Models{
}
}

@ -35,6 +35,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{
foreach (var field in data.GetType()
.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)){
if(field.GetCustomAttributes(typeof(HideInBlackboard)).Count()!=0) continue;
//if the field is MonoBehaviour,add a property field for blackboard
//skip if the field is a list or Ilist
if (!typeof(IList).IsAssignableFrom(field.FieldType)&&!field.FieldType.IsArray){
@ -86,7 +87,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{
private static void CreateBlackboardDataEntryForListItem(FieldInfo field, SerializedObject serializedObject,
bool isRuntimeGraph,
BlackboardSection blackboardSection, int index){
var property = serializedObject.FindProperty("model");
var property = serializedObject.FindProperty("data");
property = property.FindPropertyRelative(field.Name).GetArrayElementAtIndex(index);
BlackboardDataEntry entry = new BlackboardDataEntry(field.FieldType){
@ -112,7 +113,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{
var foldoutData = new Foldout{
};
var drawer =
new GraphBlackboardPropertyField(serializedObject.FindProperty("model").FindPropertyRelative(field.Name),
new GraphBlackboardPropertyField(serializedObject.FindProperty("data").FindPropertyRelative(field.Name),
isRuntimeGraph);
drawer.Bind(serializedObject);
foldoutData.Add(drawer);

@ -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{
@ -211,7 +215,33 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
AddPlacemat(placematData);
});
if (this.selection.Any()){
evt.menu.AppendAction("Comment", dma => {
BuildCommentForSelected();
});
evt.menu.AppendAction("Delete", dma => {
DeleteSelected();
});
}
});
}
private void BuildCommentForSelected(){
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(){
throw new NotImplementedException();
}
private void AddPlacemat(PlacematModel model){
@ -294,7 +324,9 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
text = "Run Once"
};
runButton.RegisterCallback<ClickEvent>(evt => {
Debug.Log(IsRuntimeGraph);
if (IsRuntimeGraph){
_runtimeGraph.TraverseAll();
AfterGraphResolved?.Invoke();
}
@ -379,10 +411,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
ClearAll();
LoadPersistentGraphViewData();
if (_nodeDict == null) throw new ArgumentNullException(nameof(_nodeDict));
foreach (var dataNode in _data.NodeDictionary.Values){
if(dataNode==null)
continue;
@ -424,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();
}
@ -548,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(){
@ -765,6 +813,8 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{
}
public class DataChangedEventArgs<T>{
public DataChangedEventArgs(T data){
NewData = data;

Loading…
Cancel
Save