From 032288c379797cf567d88d65e9643f894ee9226d Mon Sep 17 00:00:00 2001 From: taoria <445625470@qq.com> Date: Thu, 25 Aug 2022 18:56:28 +0800 Subject: [PATCH] fix:fix bug of runtime conditional runtime node --- .../RuntimeModels/ConditionalRuntimeNode.cs | 15 +++++++-------- TNodeCore/Runtime/RuntimeModels/RuntimeNode.cs | 1 + TNodeCore/Runtime/RuntimeModels/StaticGraph.cs | 4 ++++ Tests/StaticGraphTest.cs | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/TNodeCore/Runtime/RuntimeModels/ConditionalRuntimeNode.cs b/TNodeCore/Runtime/RuntimeModels/ConditionalRuntimeNode.cs index a2e6922..6a15c5f 100644 --- a/TNodeCore/Runtime/RuntimeModels/ConditionalRuntimeNode.cs +++ b/TNodeCore/Runtime/RuntimeModels/ConditionalRuntimeNode.cs @@ -20,13 +20,9 @@ namespace TNodeCore.Runtime{ $" TransitionCondition found {transitionPort.Count()} output port with" + $" type of TransitionCondition but totally {enumerable.Count()} output port found"); } - foreach (var port in transitionPort){ if(GetPortDirection(port)==Direction.Input) continue; - var ids = OutputLinks.Where(x => x.outPort.portEntryName == port).Select(x => x.inPort.nodeDataId); - var enumerable1 = ids as string[] ?? ids.ToArray(); - if(enumerable1.FirstOrDefault()!=null) - _possibleTransition.Add(new Tuple>(enumerable1.FirstOrDefault(),() => (TransitionCondition)GetOutput(port)) ); + _possibleTransition.Add(new Tuple>(port,() => (TransitionCondition)GetOutput(port)) ); } } else{ @@ -35,9 +31,11 @@ namespace TNodeCore.Runtime{ } public string[] GetConditionalNextIds(){ - var ports = _possibleTransition.Where(x => x.Item2().Condition); - return ports.Select(x => x.Item1).ToArray(); + var portNames = ports.Select(x => x.Item1); + //Search output links to found the link contains portNames as outport's name + var outputLinks = OutputLinks.Where(x => portNames.Contains(x.outPort.portEntryName)); + return outputLinks.Select(x => x.inPort.nodeDataId).ToArray(); } public string GetNextNodeId(){ @@ -48,7 +46,8 @@ namespace TNodeCore.Runtime{ var compareTo = b.Item2.Priority.CompareTo(a.Item2.Priority); return compareTo; }); - return possibleCondition.FirstOrDefault()?.Item1; + var portName = possibleCondition.FirstOrDefault()?.Item1; + return OutputLinks.Where(x => x.outPort.portEntryName == portName).Select(x => x.inPort.nodeDataId).FirstOrDefault(); } } diff --git a/TNodeCore/Runtime/RuntimeModels/RuntimeNode.cs b/TNodeCore/Runtime/RuntimeModels/RuntimeNode.cs index 6ff120c..6eeddac 100644 --- a/TNodeCore/Runtime/RuntimeModels/RuntimeNode.cs +++ b/TNodeCore/Runtime/RuntimeModels/RuntimeNode.cs @@ -18,6 +18,7 @@ namespace TNodeCore.Runtime{ //Cache node data type for fast access private readonly Type _type; public Type NodeType => _type; + public Type GetElementTypeOfPort(string portName,bool multi = false){ var type = _portAccessors[portName].Type; diff --git a/TNodeCore/Runtime/RuntimeModels/StaticGraph.cs b/TNodeCore/Runtime/RuntimeModels/StaticGraph.cs index 7042311..a08cdfe 100644 --- a/TNodeCore/Runtime/RuntimeModels/StaticGraph.cs +++ b/TNodeCore/Runtime/RuntimeModels/StaticGraph.cs @@ -4,6 +4,7 @@ using System.Linq; using TNode.TNodeCore.Runtime.Models; using TNode.TNodeCore.Runtime.Tools; using TNodeCore.Runtime.Models; +using UnityEngine; namespace TNodeCore.Runtime.RuntimeModels{ public class StaticGraph:IRuntimeNodeGraph{ @@ -17,8 +18,10 @@ namespace TNodeCore.Runtime.RuntimeModels{ var outNodeId = linkData.outPort.nodeDataId; var outNode = _nodes[outNodeId]; outNode.OutputLinks.Add(linkData); + var inNodeId = linkData.inPort.nodeDataId; var inNode = _nodes[inNodeId]; + Debug.Log($"{inNode},{outNode}"); inNode.InputLinks.Add(linkData); } public StaticGraph(GraphData graphData){ @@ -45,6 +48,7 @@ namespace TNodeCore.Runtime.RuntimeModels{ } foreach (var link in links){ ModifyLinks(link); + } _graphTool = new GraphTool(this); _runtimeNodeEnumerator = _graphTool.BreathFirstSearch(); diff --git a/Tests/StaticGraphTest.cs b/Tests/StaticGraphTest.cs index c5d9e0f..addf6d2 100644 --- a/Tests/StaticGraphTest.cs +++ b/Tests/StaticGraphTest.cs @@ -172,7 +172,7 @@ namespace Tests{ staticGraph.MoveNext(); Assert.AreEqual(node3,staticGraph.CurrentNode()); staticGraph.MoveNext(); - Assert.AreEqual(node3,staticGraph.CurrentNode()); + Assert.AreEqual(node6,staticGraph.CurrentNode()); }