feature: add a function for node that could run unity built in coroutine

main
taoria 3 years ago
parent a0c1cf7d03
commit 049f9c1e84
  1. 10
      TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs
  2. 5
      TNode/TNodeCore/Runtime/Models/NodeData.cs
  3. 12
      TNode/TNodeCore/Runtime/RuntimeNode.cs

@ -36,6 +36,8 @@ namespace TNodeCore.Components{
[NonSerialized]
public readonly List<RuntimeNode> TopologicalOrder = new List<RuntimeNode>();
public RuntimeGraph Parent;
/// <summary>
/// Entry nodes of the graph. These are the nodes that has no input.
/// </summary>
@ -100,8 +102,7 @@ namespace TNodeCore.Components{
return;
}
runtimeNode.NodeData.Process();
Parent.StartCoroutine(runtimeNode.NodeData.AfterProcess());
}
/// <summary>
/// Max depth of dependency traversal,in case of some special situation. the dependency level bigger than this number will be considered as a loop.
@ -133,8 +134,9 @@ namespace TNodeCore.Components{
/// <param name="list">List of nodes you need to traversal to build graph tool</param>
/// <param name="graphNodes">Map stores the mapping of node data id to runtime node</param>
public GraphTool(List<RuntimeNode> list, Dictionary<string, RuntimeNode> graphNodes){
public GraphTool(List<RuntimeNode> list, Dictionary<string, RuntimeNode> graphNodes,RuntimeGraph graph){
RuntimeNodes = graphNodes;
Parent = graph;
if (list == null) return;
Queue<RuntimeNode> queue = new Queue<RuntimeNode>();
Dictionary<string,int> inDegreeCounterForTopologicalSort = new Dictionary<string, int>();
@ -195,7 +197,7 @@ namespace TNodeCore.Components{
}
Debug.Log("hi");
var nodeList = RuntimeNodes.Values;
_graphTool = new GraphTool(nodeList.ToList(),RuntimeNodes);
_graphTool = new GraphTool(nodeList.ToList(),RuntimeNodes,this);
var sceneNodes = RuntimeNodes.Values.Where(x => x.NodeData is SceneNodeData).Select(x => x.NodeData as SceneNodeData);
foreach (var sceneNode in sceneNodes){
if (sceneNode != null) sceneNode.BlackboardData = runtimeBlackboardData;

@ -1,4 +1,5 @@
using System;
using System.Collections;
using TNodeCore.Attribute;
using UnityEngine;
@ -25,6 +26,10 @@ namespace TNodeCore.Models{
public virtual void Process(){
}
public virtual IEnumerator AfterProcess(){
yield return null;
}
#if UNITY_EDITOR
[HideInInspector] public bool isTest;

@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Codice.Client.Common.TreeGrouper;
@ -29,11 +30,6 @@ namespace TNodeCore.Runtime{
_portAccessors[portName].SetValue(this.NodeData,value);
}
}
public object GetOutput(string portName){
@ -42,7 +38,7 @@ namespace TNodeCore.Runtime{
private readonly Dictionary<string, IModelPropertyAccessor> _portAccessors;
public Action Process;
public RuntimeNode(NodeData nodeData){
NodeData = nodeData;
@ -51,6 +47,10 @@ namespace TNodeCore.Runtime{
var info = nodeData.GetType().GetProperties();
_portAccessors = RuntimeCache.RuntimeCache.Instance.CachedPropertyAccessors[_type];
}
public List<string> GetInputNodesId(){
List<string> dependencies = new List<string>();

Loading…
Cancel
Save