From 9bff88d22838cbe8256e7b489e626b078598cd8a Mon Sep 17 00:00:00 2001 From: taoria <445625470@qq.com> Date: Wed, 24 Aug 2022 20:22:35 +0800 Subject: [PATCH] fix:gonna fix conditional error --- Samples/New HelloGraph.asset | 26 ++++++++++++++----- .../RuntimeModels/ConditionalRuntimeNode.cs | 2 ++ TNodeCore/Runtime/Tools/GraphTool.cs | 5 ++-- Tests/StaticGraphTest.cs | 20 +++----------- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/Samples/New HelloGraph.asset b/Samples/New HelloGraph.asset index 0a2b498..2d5317e 100644 --- a/Samples/New HelloGraph.asset +++ b/Samples/New HelloGraph.asset @@ -17,6 +17,7 @@ MonoBehaviour: - id: 1 - id: 2 - id: 3 + - id: 4 nodeLinks: - inPort: portEntryName: A @@ -37,11 +38,11 @@ MonoBehaviour: portEntryName: C nodeDataId: 4300534d-023d-4b56-a0cb-39e197e68845 blackboardData: - id: 4 + id: 5 sceneReference: editorModels: [] graphViewModel: - id: 5 + id: 6 references: version: 1 00000000: @@ -83,7 +84,7 @@ MonoBehaviour: data: positionInView: serializedVersion: 2 - x: 774 + x: 781 y: 252 width: 0 height: 0 @@ -96,7 +97,7 @@ MonoBehaviour: data: positionInView: serializedVersion: 2 - x: 904 + x: 908 y: 252 width: 0 height: 0 @@ -105,6 +106,19 @@ MonoBehaviour: entryPoint: 0 isTest: 0 00000004: + type: {class: AddNode, ns: Samples.Nodes, asm: Assembly-CSharp} + data: + positionInView: + serializedVersion: 2 + x: 1119 + y: 210 + width: 0 + height: 0 + id: 926f2eea-3403-4663-88bd-7ed16ce029fa + nodeName: AddNode + entryPoint: 0 + isTest: 0 + 00000005: type: {class: HelloBlackboard, ns: TNode.Samples, asm: Assembly-CSharp} data: positionInView: @@ -119,7 +133,7 @@ MonoBehaviour: Value: - 11 - 102.1 - 00000005: + 00000006: type: {class: GraphViewModel, ns: TNode.TNodeCore.Editor.Models, asm: Taoria.TNodeCore.Runtime} data: positionInView: @@ -130,5 +144,5 @@ MonoBehaviour: height: 0 id: persistScale: 1 - persistOffset: {x: -136, y: 40} + persistOffset: {x: -212, y: 19} isBlackboardOn: 1 diff --git a/TNodeCore/Runtime/RuntimeModels/ConditionalRuntimeNode.cs b/TNodeCore/Runtime/RuntimeModels/ConditionalRuntimeNode.cs index a1f1f68..a2e6922 100644 --- a/TNodeCore/Runtime/RuntimeModels/ConditionalRuntimeNode.cs +++ b/TNodeCore/Runtime/RuntimeModels/ConditionalRuntimeNode.cs @@ -20,6 +20,7 @@ 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); @@ -34,6 +35,7 @@ namespace TNodeCore.Runtime{ } public string[] GetConditionalNextIds(){ + var ports = _possibleTransition.Where(x => x.Item2().Condition); return ports.Select(x => x.Item1).ToArray(); } diff --git a/TNodeCore/Runtime/Tools/GraphTool.cs b/TNodeCore/Runtime/Tools/GraphTool.cs index e5e7c62..b0a3269 100644 --- a/TNodeCore/Runtime/Tools/GraphTool.cs +++ b/TNodeCore/Runtime/Tools/GraphTool.cs @@ -158,10 +158,11 @@ namespace TNode.TNodeCore.Runtime.Tools{ //Conditional node will be traversed in a special way,only links fit the condition will be traversed if (node is ConditionalRuntimeNode conditionalRuntimeNode){ var ids = conditionalRuntimeNode.GetConditionalNextIds(); - + var nextNodes = ids.Select(id=>RuntimeNodes[id]).ToList(); - + foreach (var runtimeNode in nextNodes){ + AddToCollectionIfMeetCondition(alreadyContained, visited,runtimeNode, queue); } } diff --git a/Tests/StaticGraphTest.cs b/Tests/StaticGraphTest.cs index 026d920..c5d9e0f 100644 --- a/Tests/StaticGraphTest.cs +++ b/Tests/StaticGraphTest.cs @@ -27,6 +27,7 @@ namespace Tests{ public object In{ get; set; } [Output] public TransitionCondition Output(){ + Debug.Log($"Test Condition is {TestCondition}"); return new TransitionCondition(){ Condition = TestCondition }; @@ -160,6 +161,7 @@ namespace Tests{ node3.TestCondition = true; var staticGraph = new StaticGraph(graphData); + staticGraph.AccessMethod = AccessMethod.Bfs; Assert.AreEqual(node1,staticGraph.CurrentNode()); staticGraph.MoveNext(); Assert.AreEqual(node4,staticGraph.CurrentNode()); @@ -170,22 +172,8 @@ namespace Tests{ staticGraph.MoveNext(); Assert.AreEqual(node3,staticGraph.CurrentNode()); staticGraph.MoveNext(); - Assert.AreEqual(node6,staticGraph.CurrentNode()); - - node3.TestCondition = false; - - var staticGraph2 = new StaticGraph(graphData); - Assert.AreEqual(node1,staticGraph2.CurrentNode()); - staticGraph2.MoveNext(); - Assert.AreEqual(node4,staticGraph2.CurrentNode()); - staticGraph2.MoveNext(); - Assert.AreEqual(node5,staticGraph2.CurrentNode()); - staticGraph2.MoveNext(); - Assert.AreEqual(node2,staticGraph2.CurrentNode()); - staticGraph2.MoveNext(); - Assert.AreEqual(node3,staticGraph2.CurrentNode()); - staticGraph2.MoveNext(); - Assert.AreNotEqual(node6,staticGraph2.CurrentNode()); + Assert.AreEqual(node3,staticGraph.CurrentNode()); + } [Test]