Ejemplo n.º 1
0
        public void SmallerThanTest()
        {
            FsmParameter int1 = FsmParameter.NewInteger("int1", 1);

            Assert.IsFalse(int1.SmallerThan(0));
            Assert.IsFalse(int1.SmallerThan(1));
            Assert.IsTrue(int1.SmallerThan(2));
        }
Ejemplo n.º 2
0
        public void IntegerContainsTest()
        {
            FsmParameter int1      = FsmParameter.NewInteger("int1");
            FsmParameter int2      = FsmParameter.NewInteger("int2");
            FsmCondition condition = FsmCondition.NewEquals(int1, 0);

            Assert.IsTrue(condition.Contains("int1"));
            Assert.IsFalse(condition.Contains("int2"));
        }
Ejemplo n.º 3
0
        public void SetUp()
        {
            fsm = ScriptableObject.CreateInstance <FiniteStateMachine>();

            LoggerFsmState state1 = ScriptableObject.CreateInstance <LoggerFsmState>();

            state1.name = "State1";
            AssetDatabase.CreateAsset(state1, ASSET_PATH + "State1.asset");

            LoggerFsmState state2 = ScriptableObject.CreateInstance <LoggerFsmState>();

            state2.name = "State2";
            AssetDatabase.CreateAsset(state2, ASSET_PATH + "State2.asset");
            AssetDatabase.SaveAssets();

            fsm.AddStateInstance("One", state1);
            fsm.AddStateInstance("Two", state2);

            fsm.AddStateInstance("Three", state1);
            fsm.AddStateInstance("Four", state2);

            FsmParameter triggerParameter = FsmParameter.NewBoolean("testTrigger");
            FsmParameter booleanParameter = FsmParameter.NewBoolean("testBool");
            FsmParameter integerParameter = FsmParameter.NewInteger("testInt");
            FsmParameter floatParameter   = FsmParameter.NewFloat("testFloat");

            fsm.AddParameter(triggerParameter);
            fsm.AddParameter(booleanParameter);
            fsm.AddParameter(integerParameter);
            fsm.AddParameter(floatParameter);

            FsmTransition transition1to2 = new FsmTransition();

            transition1to2.AddCondition(FsmCondition.NewTrigger(triggerParameter));

            FsmTransition transition2to3 = new FsmTransition();

            transition2to3.AddCondition(FsmCondition.NewEquals(booleanParameter, true));

            FsmTransition transition3to4 = new FsmTransition();

            transition3to4.AddCondition(FsmCondition.NewGreaterThan(integerParameter, 3));

            FsmTransition transition4to1 = new FsmTransition();

            transition4to1.AddCondition(FsmCondition.NewSmallerThan(floatParameter, -1f));

            fsm.AddTransition("One", "Two", transition1to2);
            fsm.AddTransition("Two", "Three", transition2to3);
            fsm.AddTransition("Three", "Four", transition3to4);
            fsm.AddTransition("Four", "One", transition4to1);

            // Clean up if asset already exists
            AssetDatabase.DeleteAsset(ASSET_PATH);
        }
Ejemplo n.º 4
0
        public void EqualsTest()
        {
            FsmParameter int1 = FsmParameter.NewInteger("int1", 1);

            Assert.IsTrue(int1.Equals(1));
            Assert.IsFalse(int1.Equals(2));

            int1.intValue = 2;

            Assert.IsFalse(int1.Equals(1));
            Assert.IsTrue(int1.Equals(2));
        }
Ejemplo n.º 5
0
        public void SetUp()
        {
            fsm = ScriptableObject.CreateInstance <FiniteStateMachine>();

            state1      = ScriptableObject.CreateInstance <TestFsmState>();
            state1.name = "State1";
            state2      = ScriptableObject.CreateInstance <TestFsmState>();
            state2.name = "State2";

            fsm.AddStateInstance("One", state1);
            fsm.AddStateInstance("Two", state2);
            fsm.AddStateInstance("Three", state1);
            fsm.AddStateInstance("Four", state2);

            triggerParameter = FsmParameter.NewBoolean("testTrig");
            booleanParameter = FsmParameter.NewBoolean("testBool");
            integerParameter = FsmParameter.NewInteger("testInt");
            floatParameter   = FsmParameter.NewFloat("testFloat");

            fsm.AddParameter(triggerParameter);
            fsm.AddParameter(booleanParameter);
            fsm.AddParameter(integerParameter);
            fsm.AddParameter(floatParameter);

            transition1to2 = new FsmTransition();
            transition1to2.AddCondition(FsmCondition.NewTrigger(triggerParameter));

            transition2to3 = new FsmTransition();
            FsmCondition equalsCondition = FsmCondition.NewEquals(booleanParameter, true);

            transition2to3.AddCondition(equalsCondition);

            transition3to4 = new FsmTransition();
            FsmCondition greaterCondition = FsmCondition.NewGreaterThan(integerParameter, 3);

            transition3to4.AddCondition(greaterCondition);

            transition4to1 = new FsmTransition();
            FsmCondition smallerCondition = FsmCondition.NewSmallerThan(floatParameter, -1f);

            transition4to1.AddCondition(smallerCondition);

            fsm.AddTransition("One", "Two", transition1to2);
            fsm.AddTransition("Two", "Three", transition2to3);
            fsm.AddTransition("Three", "Four", transition3to4);
            fsm.AddTransition("Four", "One", transition4to1);
        }
Ejemplo n.º 6
0
        public void IntegerEvaluationTest()
        {
            FsmParameter int1      = FsmParameter.NewInteger("int1");
            FsmCondition condition = FsmCondition.NewSmallerThan(int1, 0);

            int1.intValue      = 0;
            condition.intValue = 0;
            Assert.IsFalse(condition.Evaluate());

            int1.intValue      = 0;
            condition.intValue = 1;
            Assert.IsTrue(condition.Evaluate());

            int1.intValue      = 1;
            condition.intValue = 0;
            Assert.IsFalse(condition.Evaluate());
        }