fix:gonna fix conditional error

main
taoria 3 years ago
parent f6af4e7390
commit 9bff88d228
  1. 26
      Samples/New HelloGraph.asset
  2. 2
      TNodeCore/Runtime/RuntimeModels/ConditionalRuntimeNode.cs
  3. 5
      TNodeCore/Runtime/Tools/GraphTool.cs
  4. 20
      Tests/StaticGraphTest.cs

@ -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

@ -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();
}

@ -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);
}
}

@ -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]

Loading…
Cancel
Save