示例#1
0
        public void BooleanContainsTest()
        {
            FsmParameter bool1     = FsmParameter.NewBoolean("bool1");
            FsmParameter bool2     = FsmParameter.NewBoolean("bool2");
            FsmCondition condition = FsmCondition.NewEquals(bool1, false);

            Assert.IsTrue(condition.Contains("bool1"));
            Assert.IsFalse(condition.Contains("bool2"));
        }
示例#2
0
        public void FloatContainsTest()
        {
            FsmParameter float1    = FsmParameter.NewFloat("float1");
            FsmParameter float2    = FsmParameter.NewFloat("float2");
            FsmCondition condition = FsmCondition.NewEquals(float1, 0f);

            Assert.IsTrue(condition.Contains("float1"));
            Assert.IsFalse(condition.Contains("float2"));
        }
示例#3
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"));
        }
示例#4
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);
        }
        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);
        }
示例#6
0
        public void BooleanEvaluationTest()
        {
            FsmParameter bool1     = FsmParameter.NewBoolean("bool1");
            FsmCondition condition = FsmCondition.NewEquals(bool1, false);

            bool1.boolValue     = false;
            condition.boolValue = false;
            Assert.IsTrue(condition.Evaluate());

            bool1.boolValue     = false;
            condition.boolValue = true;
            Assert.IsFalse(condition.Evaluate());

            bool1.boolValue     = true;
            condition.boolValue = false;
            Assert.IsFalse(condition.Evaluate());

            bool1.boolValue     = true;
            condition.boolValue = true;
            Assert.IsTrue(condition.Evaluate());
        }
示例#7
0
        public void FloatEvaluationTest()
        {
            FsmParameter float1    = FsmParameter.NewFloat("float1");
            FsmCondition condition = FsmCondition.NewEquals(float1, 1f);

            float1.floatValue    = 0f;
            condition.floatValue = 0f;
            Assert.IsTrue(condition.Evaluate());

            float1.floatValue    = 0f;
            condition.floatValue = 1f;
            Assert.IsFalse(condition.Evaluate());

            float1.floatValue    = 1f;
            condition.floatValue = 0f;
            Assert.IsFalse(condition.Evaluate());

            float1.floatValue    = 1f;
            condition.floatValue = 1f;
            Assert.IsTrue(condition.Evaluate());
        }
示例#8
0
        public void IntegerEvaluationTest()
        {
            FsmParameter int1      = FsmParameter.NewInteger("int1");
            FsmCondition condition = FsmCondition.NewEquals(int1, 0);

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

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

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

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