示例#1
0
        public void Test_EditPropertyGroupNodeAction_AddRemove([Values] TestingMode mode)
        {
            IConstantNodeModel        constant = GraphModel.CreateConstantNode("toto", typeof(Vector3).GenerateTypeHandle(Stencil), Vector2.zero);
            GetPropertyGroupNodeModel property = GraphModel.CreateGetPropertyGroupNode(Vector2.zero);

            GraphModel.CreateEdge(property.InstancePort, constant.OutputPort);

            Type       type       = typeof(GameObject);
            MemberInfo memberInfo = type.GetMembers()[0];
            var        newMember  = new TypeMember
            {
                Path = new List <string> {
                    memberInfo.Name
                },
                Type = memberInfo.GetUnderlyingType().GenerateTypeHandle(Stencil)
            };


            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(property.GetPortsForMembers().Count(), Is.EqualTo(0));
                Assert.That(property.OutputsByDisplayOrder.Count(), Is.EqualTo(0));
                return(new EditPropertyGroupNodeAction(
                           EditPropertyGroupNodeAction.EditType.Add,
                           property,
                           newMember));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(property.GetPortsForMembers().Count(), Is.EqualTo(1));
                Assert.That(property.OutputsByDisplayOrder.Count(), Is.EqualTo(1));
            });

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(property.GetPortsForMembers().Count(), Is.EqualTo(1));
                Assert.That(property.OutputsByDisplayOrder.Count(), Is.EqualTo(1));
                return(new EditPropertyGroupNodeAction(
                           EditPropertyGroupNodeAction.EditType.Remove,
                           property,
                           newMember));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(1));
                Assert.That(property.GetPortsForMembers().Count(), Is.EqualTo(0));
                Assert.That(property.OutputsByDisplayOrder.Count(), Is.EqualTo(0));
            });
        }
        public void TestWaitUntilCoroutine([Values] CodeGenMode mode)
        {
            float yBeforeWait = 0f;
            float yAfterWait  = 10f;

            SetupTestGraphMultipleFrames(mode, graph =>
            {
                var query = SetupQuery(graph, "query", new[] { typeof(Translation) });

                var onUpdate  = SetupOnUpdate(graph, query);
                var waitUntil = onUpdate.CreateStackedNode <CoroutineNodeModel>("Wait Until", setup: n =>
                {
                    n.CoroutineType = typeof(WaitUntil).GenerateTypeHandle(Stencil);
                });
                var translation = graph.CreateVariableNode(onUpdate.FunctionParameterModels.Single(p =>
                                                                                                   p.DataType == typeof(Translation).GenerateTypeHandle(Stencil)), Vector2.zero);
                var getProperty        = GraphModel.CreateGetPropertyGroupNode(Vector2.zero);
                var translationXMember = new TypeMember(TypeHandle.Float, new List <string>
                {
                    nameof(Translation.Value), nameof(Translation.Value.x)
                });
                getProperty.AddMember(translationXMember);
                GraphModel.CreateEdge(getProperty.InstancePort, translation.OutputPort);
                var equalNode = GraphModel.CreateBinaryOperatorNode(BinaryOperatorKind.GreaterThan, Vector2.zero);
                GraphModel.CreateEdge(equalNode.InputPortA, getProperty.GetPortsForMembers().Single());
                ((FloatConstantModel)equalNode.InputConstantsById[equalNode.InputPortB.UniqueId]).value = 0f;
                var moveNextParam = typeof(WaitUntil).GetMethod(nameof(WaitUntil.MoveNext))?.GetParameters().Single();
                Assert.That(moveNextParam, Is.Not.Null);
                GraphModel.CreateEdge(waitUntil.GetParameterPort(moveNextParam), equalNode.OutputPort);

                var setProperty        = onUpdate.CreateSetPropertyGroupNode(-1);
                var translationYMember = new TypeMember(TypeHandle.Float, new List <string>
                {
                    nameof(Translation.Value), nameof(Translation.Value.y)
                });
                setProperty.AddMember(translationYMember);
                GraphModel.CreateEdge(setProperty.InstancePort, translation.OutputPort);
                ((FloatConstantModel)setProperty.InputConstantsById[translationYMember.GetId()]).value = yAfterWait;
            },
                                         EachEntity((manager, i, e) =>
            {
                manager.AddComponentData(e, new Translation());
            }),
                                         EachEntity((manager, i, e) =>
            {
                Assert.That(manager.GetComponentData <Translation>(e).Value.y, Is.EqualTo(yBeforeWait));
                manager.SetComponentData(e, new Translation {
                    Value = { x = 10f }
                });                                                 // any x > 0 should stop this WaitUntil
            }),
                                         (manager, entities) => {}, // Skip Frame where WaitUntil is done and component gets set
                                         EachEntity((manager, i, e) =>
            {
                Assert.That(manager.GetComponentData <Translation>(e).Value.y, Is.EqualTo(yAfterWait));
            })
                                         );
        }
示例#3
0
        public void ConnectingADifferentNodePreservesConnections([Values] TestingMode mode)
        {
            var memberX = new TypeMember(Stencil.GenerateTypeHandle(typeof(Vector3)), new List <string> {
                nameof(Vector3.x)
            });
            var memberY = new TypeMember(Stencil.GenerateTypeHandle(typeof(Vector3)), new List <string> {
                nameof(Vector3.y)
            });

            {
                var iDecl = GraphModel.CreateGraphVariableDeclaration("myInt", TypeHandle.Int, true);
                var myInt = GraphModel.CreateVariableNode(iDecl, Vector2.up);

                var vDecl       = GraphModel.CreateGraphVariableDeclaration("myVec", typeof(Vector3).GenerateTypeHandle(Stencil), true);
                var myVec       = GraphModel.CreateVariableNode(vDecl, Vector2.left);
                var getProperty = GraphModel.CreateGetPropertyGroupNode(Vector2.zero);
                GraphModel.CreateEdge(getProperty.InstancePort, myVec.OutputPort);

                getProperty.AddMember(memberX);
                getProperty.AddMember(memberY);

                var stack = GraphModel.CreateStack("myStack", Vector2.right);
                var log1  = stack.CreateStackedNode <LogNodeModel>("log1");
                var log2  = stack.CreateStackedNode <LogNodeModel>("log2");

                GraphModel.CreateEdge(log1.InputPort, getProperty.OutputsById[memberX.GetId()]);
                GraphModel.CreateEdge(log2.InputPort, getProperty.OutputsById[memberY.GetId()]);
            }

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                var logStack    = GetAllStacks().Single();
                var log1        = logStack.NodeModels[0] as LogNodeModel;
                var log2        = logStack.NodeModels[1] as LogNodeModel;
                var myInt       = GetAllNodes().OfType <VariableNodeModel>().Single(n => n.DataType == TypeHandle.Int);
                var getProperty = GetAllNodes().OfType <GetPropertyGroupNodeModel>().Single();
                var portX       = getProperty.OutputsById[memberX.GetId()];
                var portY       = getProperty.OutputsById[memberY.GetId()];

                Assert.That(myInt.OutputPort.Connected, Is.False);
                Assert.That(log1.InputPort, Is.ConnectedTo(portX));
                Assert.That(log2.InputPort, Is.ConnectedTo(portY));
                return(new CreateEdgeAction(log1.InputPort, myInt.OutputPort, new List <IEdgeModel> {
                    GraphModel.GetEdgesConnections(log1.InputPort).Single()
                }));
            },
                                    () =>
            {
                var logStack    = GetAllStacks().Single();
                var log1        = logStack.NodeModels[0] as LogNodeModel;
                var log2        = logStack.NodeModels[1] as LogNodeModel;
                var myInt       = GetAllNodes().OfType <VariableNodeModel>().Single(n => n.DataType == TypeHandle.Int);
                var getProperty = GetAllNodes().OfType <GetPropertyGroupNodeModel>().Single();
                var portX       = getProperty.OutputsById[memberX.GetId()];
                var portY       = getProperty.OutputsById[memberY.GetId()];

                Assert.That(myInt.OutputPort.Connected, Is.True);
                Assert.That(portX.Connected, Is.False);
                Assert.That(log1.InputPort, Is.ConnectedTo(myInt.OutputPort));
                Assert.That(log2.InputPort, Is.ConnectedTo(portY));
            });
        }