|
|
|
@ -2,14 +2,15 @@ |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
|
using TNodeCore.Models; |
|
|
|
|
using TNodeCore.Runtime; |
|
|
|
|
using UnityEngine; |
|
|
|
|
|
|
|
|
|
namespace TNodeCore.Runtime{ |
|
|
|
|
namespace TNodeCore.Components{ |
|
|
|
|
public class RuntimeGraph:MonoBehaviour{ |
|
|
|
|
public GraphData graphData; |
|
|
|
|
public List<SceneNodeData> sceneNodes; |
|
|
|
|
|
|
|
|
|
public readonly Dictionary<string, RuntimeNode> RuntimeNodes = new Dictionary<string, RuntimeNode>(); |
|
|
|
|
|
|
|
|
|
private GraphTool _graphTool; |
|
|
|
|
|
|
|
|
|
private class GraphTool{ |
|
|
|
@ -20,6 +21,15 @@ namespace TNodeCore.Runtime{ |
|
|
|
|
/// elements are read only ,do not modify them |
|
|
|
|
/// </summary> |
|
|
|
|
public readonly Dictionary<string, RuntimeNode> RuntimeNodes; |
|
|
|
|
public void DirectlyTraversal(){ |
|
|
|
|
foreach (var node in TopologicalOrder){ |
|
|
|
|
var links = node.InputLink; |
|
|
|
|
foreach (var link in links){ |
|
|
|
|
HandlingLink(link); |
|
|
|
|
} |
|
|
|
|
node.NodeData.Process(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public void DependencyTraversal(RuntimeNode runtimeNode){ |
|
|
|
|
var links = runtimeNode.InputLink; |
|
|
|
|
foreach (var link in links){ |
|
|
|
@ -37,6 +47,7 @@ namespace TNodeCore.Runtime{ |
|
|
|
|
//out node is node output data |
|
|
|
|
//in node is node receive data |
|
|
|
|
var outValue = outNode.GetOutput(nodeLink.outPort.portEntryName); |
|
|
|
|
|
|
|
|
|
inNode.SetInput(nodeLink.inPort.portEntryName, outValue); |
|
|
|
|
} |
|
|
|
|
public GraphTool(List<RuntimeNode> list, Dictionary<string, RuntimeNode> graphNodes){ |
|
|
|
@ -91,6 +102,10 @@ namespace TNodeCore.Runtime{ |
|
|
|
|
Debug.Log("hi"); |
|
|
|
|
var nodeList = RuntimeNodes.Values; |
|
|
|
|
_graphTool = new GraphTool(nodeList.ToList(),RuntimeNodes); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
_build = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -118,6 +133,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]; |
|
|
|
@ -160,6 +183,13 @@ namespace TNodeCore.Runtime{ |
|
|
|
|
RuntimeNodes.Clear(); |
|
|
|
|
_build = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Start(){ |
|
|
|
|
Build(); |
|
|
|
|
} |
|
|
|
|
public virtual void RuntimeExecute(){ |
|
|
|
|
_graphTool.DirectlyTraversal(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|