diff --git a/TNodeCore/Attribute/GraphUsageAttribute.cs b/TNodeCore/Attribute/GraphUsageAttribute.cs
index 4eb9151..62ed03f 100644
--- a/TNodeCore/Attribute/GraphUsageAttribute.cs
+++ b/TNodeCore/Attribute/GraphUsageAttribute.cs
@@ -1,6 +1,7 @@
using System;
using JetBrains.Annotations;
using TNodeCore.Models;
+using TNodeCore.Runtime.Interfaces;
namespace TNodeCore.Attribute{
///
@@ -11,8 +12,8 @@ namespace TNodeCore.Attribute{
///
///
[AttributeUsage(AttributeTargets.Class)]
- [BaseTypeRequired(typeof(IModel))]
[UsedImplicitly]
+ [MeansImplicitUse]
public class GraphUsageAttribute:System.Attribute{
public readonly Type GraphDataType;
public string Category;
diff --git a/TNodeCore/DataWrapper.cs b/TNodeCore/DataWrapper.cs
index 92ba218..c24931a 100644
--- a/TNodeCore/DataWrapper.cs
+++ b/TNodeCore/DataWrapper.cs
@@ -30,7 +30,9 @@ namespace TNodeCore{
fieldInfo.SetValue(data,value);
OnValueChanged?.Invoke(this);
}
-
+ public void ForceNotify(){
+ OnValueChanged?.Invoke(this);
+ }
public object GetValue(string path){
var fieldInfo = data.GetType().GetField(path);
return fieldInfo.GetValue(data);
diff --git a/TNodeCore/Editor/NodeGraphView/IBaseDataGraphView.cs b/TNodeCore/Editor/NodeGraphView/IBaseDataGraphView.cs
index 7e04299..7db65a6 100644
--- a/TNodeCore/Editor/NodeGraphView/IBaseDataGraphView.cs
+++ b/TNodeCore/Editor/NodeGraphView/IBaseDataGraphView.cs
@@ -1,4 +1,5 @@
-using TNodeCore.Models;
+using System;
+using TNodeCore.Models;
using TNodeCore.Runtime;
using UnityEngine;
@@ -23,6 +24,9 @@ namespace TNodeCore.Editor.NodeGraphView{
public RuntimeGraph GetRuntimeGraph();
public void SetGraphData(GraphData graph);
-
+
+ void NotifyRuntimeUpdate();
+
+ public Action AfterRuntimeGraphUpdate{ get; set; }
}
}
\ No newline at end of file
diff --git a/TNodeCore/Runtime/RuntimeGraph.cs b/TNodeCore/Runtime/RuntimeGraph.cs
index 11dd5c8..c8df9c3 100644
--- a/TNodeCore/Runtime/RuntimeGraph.cs
+++ b/TNodeCore/Runtime/RuntimeGraph.cs
@@ -20,6 +20,16 @@ namespace TNodeCore.Runtime{
/// elements are read only ,do not modify them
///
public readonly Dictionary RuntimeNodes;
+ public void DirectlyTraversal(){
+ foreach (var node in TopologicalOrder){
+ var links = node.OutputLink;
+ foreach (var link in links){
+ var targetNode = RuntimeNodes[link.inPort.nodeDataId];
+ HandlingLink(link);
+ targetNode.NodeData.Process();
+ }
+ }
+ }
public void DependencyTraversal(RuntimeNode runtimeNode){
var links = runtimeNode.InputLink;
foreach (var link in links){
@@ -118,6 +128,14 @@ namespace TNodeCore.Runtime{
_graphTool.DependencyTraversal(Get(startNode));
return true;
}
+ public bool ResolveDependency(){
+ if(!_build)
+ Build();
+ if (_graphTool == null)
+ return false;
+ _graphTool.DirectlyTraversal();
+ return true;
+ }
private void ModifyOrCreateInNode(NodeLink linkData){
var inNodeId = linkData.inPort.nodeDataId;
var inNode = graphData.NodeDictionary[inNodeId];
diff --git a/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs b/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs
index 499bc5c..2f1a20b 100644
--- a/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs
+++ b/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs
@@ -30,11 +30,11 @@ namespace TNodeGraphViewImpl.Editor.GraphBlackboard{
//skip if the field is a list or Ilist
if (!typeof(IList).IsAssignableFrom(field.FieldType)){
VisualElement visualElement = new VisualElement();
- var propertyField = new BlackboardField(new BlackboardProperty.BlackboardProperty(field.Name,field.FieldType));
+ var propertyField = new BlackboardField(new BlackboardProperty.BlackboardProperty(ObjectNames.NicifyVariableName(field.Name),field.FieldType));
var foldoutData = new Foldout{
- text = field.Name
+ text = ObjectNames.NicifyVariableName(field.Name)
};
- var drawer = new GraphBlackboardPropertyField(serializedObject.FindProperty("data").FindPropertyRelative(field.Name),field.Name,isRuntimeGraph);
+ var drawer = new GraphBlackboardPropertyField(serializedObject.FindProperty("data").FindPropertyRelative(field.Name),isRuntimeGraph);
drawer.Bind(serializedObject);
foldoutData.Add(drawer);
visualElement.Add(propertyField);
diff --git a/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardPropertyField.cs b/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardPropertyField.cs
index 33c40e6..75e4b2c 100644
--- a/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardPropertyField.cs
+++ b/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardPropertyField.cs
@@ -6,7 +6,7 @@ namespace TNodeGraphViewImpl.Editor.GraphBlackboard{
public class GraphBlackboardPropertyField:PropertyField{
private readonly bool _runtime;
- public GraphBlackboardPropertyField(SerializedProperty findPropertyRelative, string fieldName,bool runtime):base(findPropertyRelative, fieldName){
+ public GraphBlackboardPropertyField(SerializedProperty findPropertyRelative,bool runtime):base(findPropertyRelative){
_runtime = runtime;
}
diff --git a/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs b/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs
index 1c03a31..8581d05 100644
--- a/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs
+++ b/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs
@@ -51,7 +51,12 @@ namespace TNode.Editor.Inspector{
var showInNodeViewAttribute = field.GetCustomAttribute() != null;
if (!showInNodeViewAttribute)
continue;
- var drawer = new PropertyField(serializedObject.FindProperty("data").FindPropertyRelative(field.Name),field.Name);
+ var drawer = new PropertyField(serializedObject.FindProperty("data").FindPropertyRelative(field.Name));
+ drawer.RegisterValueChangeCallback((evt) => {
+ serializedObject.Update();
+ serializedObject.ApplyModifiedProperties();
+ ((NodeDataWrapper)_data).ForceNotify();
+ });
drawer.Bind(serializedObject);
Add(drawer);
diff --git a/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs b/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs
index 49b4e97..0fd9fb7 100644
--- a/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs
+++ b/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
+using System.Threading.Tasks;
using TNode.Editor.Inspector;
using TNodeCore.Editor.Blackboard;
using TNodeCore.Editor.EditorPersistence;
@@ -14,6 +15,7 @@ using TNodeEditor.Editor;
using TNodeGraphViewImpl.Editor.Cache;
using TNodeGraphViewImpl.Editor.NodeViews;
using TNodeGraphViewImpl.Editor.Search;
+using Unity.VisualScripting;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
@@ -32,6 +34,8 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{
private NodeInspector _nodeInspector;
private Dictionary _nodeDict = new();
private IBlackboardView _blackboard;
+ private bool _runtimeGraphUpdate;
+
public T Data{
get{ return _data; }
set{
@@ -106,8 +110,7 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{
_runtimeGraph = gameObject.GetComponent();
IsRuntimeGraph = true;
-
-
+ BuildRuntimeGraphBehaviour();
Data = gameObject.GetComponent().graphData as T;
if(Data==null){
Debug.LogError($"Dragged a wrong graph data to editor,expected {typeof(T)} but got {gameObject.GetComponent().graphData.GetType()}");
@@ -143,6 +146,27 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{
}
};
}
+
+ private void BuildRuntimeGraphBehaviour(){
+ EditorApplication.update+= UpdateRuntimeGraphBehaviour;
+
+ }
+
+ private void UpdateRuntimeGraphBehaviour(){
+ if(_runtimeGraph != null){
+ if (_runtimeGraphUpdate){
+ _runtimeGraph.ResolveDependency();
+ _runtimeGraphUpdate = false;
+ AfterRuntimeGraphUpdate?.Invoke();
+ }
+
+
+ }
+ else{
+ EditorApplication.update -= UpdateRuntimeGraphBehaviour;
+ }
+ }
+
private void CheckDataAfterInit(){
if(Data == null){
WaitingForAGraph();
@@ -521,6 +545,13 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{
Data = graph as T;
}
+ public void NotifyRuntimeUpdate(){
+
+ _runtimeGraphUpdate = true;
+ }
+
+ public Action AfterRuntimeGraphUpdate{ get; set; }
+
#endregion
}
diff --git a/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs b/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs
index a48bb79..4ab71dc 100644
--- a/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs
+++ b/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs
@@ -26,19 +26,10 @@ namespace TNode.Editor.NodeViews{
var serializedData = new SerializedObject(blackboardWrapper);
var serializedProperty = serializedData.FindProperty("data").FindPropertyRelative(obj.blackDragData);
- //
- // field.Bind(serializedData);
- // var p = label.parent.parent.parent;
- // p.Add(field);
- // field.SendToBack();
- // field.SetEnabled(false);
- // p.style.alignItems = Align.Center;
- // p.style.justifyContent = Justify.Center;
- // p.style.paddingTop = 0;
- // p.style.paddingBottom = 0;
- label.text = obj.blackDragData;
+ label.text = ObjectNames.NicifyVariableName(obj.blackDragData);
+
//Get serialized property's icon
- var icon = AssetPreview.GetMiniThumbnail(serializedProperty.objectReferenceValue);
+ var icon = AssetPreview.GetMiniThumbnail(serializedProperty.boxedValue as UnityEngine.Object);
label.parent.Add(new Image(){
image = icon
diff --git a/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs b/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs
index c3bef2f..298df16 100644
--- a/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs
+++ b/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs
@@ -7,6 +7,7 @@ using TNodeCore.Attribute.Ports;
using TNodeCore.Editor.NodeGraphView;
using TNodeCore.Editor.Serialization;
using TNodeCore.Models;
+using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
@@ -38,6 +39,9 @@ namespace TNodeGraphViewImpl.Editor.NodeViews{
private void OnDataValueChanged(DataWrapper obj){
Refresh();
+ if (BaseDataGraphView.IsRuntimeGraph){
+ BaseDataGraphView.NotifyRuntimeUpdate();
+ }
}
public sealed override string title{
get => base.title;
@@ -103,7 +107,7 @@ namespace TNodeGraphViewImpl.Editor.NodeViews{
if (propertyInfo.GetCustomAttributes(typeof(OutputAttribute),true).FirstOrDefault() is OutputAttribute attribute){
Port port = InstantiatePort(Orientation.Horizontal, Direction.Output,Port.Capacity.Multi,BuildPortType(attribute,propertyInfo));
this.outputContainer.Add(port);
- var portName = BuildPortName(attribute,propertyInfo);
+ var portName = ObjectNames.NicifyVariableName(BuildPortName(attribute,propertyInfo));
port.portName = portName;
port.name = propertyInfo.Name;
diff --git a/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs b/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs
index d2f2af7..28cf940 100644
--- a/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs
+++ b/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs
@@ -54,7 +54,7 @@ namespace TNodeGraphViewImpl.Editor.Search{
if (typeof(NodeData).IsAssignableFrom(type)){
//Make an instance of the type
if (NodeCreator.InstantiateNodeData(type) is { } nodeData){
- nodeData.nodeName = $"New {type.Name}";
+ nodeData.nodeName = $"{type.Name}";
((IBaseDataGraphView) _graphView).AddTNode(nodeData, new Rect(localPos.x, localPos.y, 100, 100));
}
}