Esempio n. 1
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);
        }
Esempio n. 2
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);
        }