From 049f9c1e843fb71e17d7de9b949d81a2a392fb08 Mon Sep 17 00:00:00 2001 From: taoria <445625470@qq.com> Date: Sat, 30 Jul 2022 13:51:46 +0800 Subject: [PATCH] feature: add a function for node that could run unity built in coroutine --- TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs | 10 ++++++---- TNode/TNodeCore/Runtime/Models/NodeData.cs | 5 +++++ TNode/TNodeCore/Runtime/RuntimeNode.cs | 12 ++++++------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs b/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs index cdbf8ad..3457973 100644 --- a/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs +++ b/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs @@ -35,6 +35,8 @@ namespace TNodeCore.Components{ /// [NonSerialized] public readonly List TopologicalOrder = new List(); + + public RuntimeGraph Parent; /// /// Entry nodes of the graph. These are the nodes that has no input. @@ -100,8 +102,7 @@ namespace TNodeCore.Components{ return; } runtimeNode.NodeData.Process(); - - + Parent.StartCoroutine(runtimeNode.NodeData.AfterProcess()); } /// /// 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{ /// List of nodes you need to traversal to build graph tool /// Map stores the mapping of node data id to runtime node - public GraphTool(List list, Dictionary graphNodes){ + public GraphTool(List list, Dictionary graphNodes,RuntimeGraph graph){ RuntimeNodes = graphNodes; + Parent = graph; if (list == null) return; Queue queue = new Queue(); Dictionary inDegreeCounterForTopologicalSort = new Dictionary(); @@ -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; diff --git a/TNode/TNodeCore/Runtime/Models/NodeData.cs b/TNode/TNodeCore/Runtime/Models/NodeData.cs index 5701a69..08d9501 100644 --- a/TNode/TNodeCore/Runtime/Models/NodeData.cs +++ b/TNode/TNodeCore/Runtime/Models/NodeData.cs @@ -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; diff --git a/TNode/TNodeCore/Runtime/RuntimeNode.cs b/TNode/TNodeCore/Runtime/RuntimeNode.cs index 5a6bd1b..92b52f1 100644 --- a/TNode/TNodeCore/Runtime/RuntimeNode.cs +++ b/TNode/TNodeCore/Runtime/RuntimeNode.cs @@ -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 _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 GetInputNodesId(){ List dependencies = new List();