Esempio n. 1
0
    private void MakeFSM()
    {
        IdleState idle = new IdleState();

        idle.AddTransition(Transition.Walk, StateID.Walk);
        idle.AddTransition(Transition.Jump, StateID.Jump);
        idle.AddTransition(Transition.Die, StateID.Die);

        WalkState walk = new WalkState(path);

        walk.AddTransition(Transition.Idle, StateID.Idle);
        walk.AddTransition(Transition.Jump, StateID.Jump);
        walk.AddTransition(Transition.Die, StateID.Die);

        JumpState jump = new JumpState();

        jump.AddTransition(Transition.Idle, StateID.Idle);
        jump.AddTransition(Transition.Die, StateID.Die);
        DeadState die = new DeadState();

        fsm = new FSMSystem();
        fsm.AddState(idle);
        fsm.AddState(walk);
        fsm.AddState(jump);
        fsm.AddState(die);
    }
Esempio n. 2
0
    private void ConstructFSM()
    {
        /*
         * //Get the list of points
         * pointList = GameObject.FindGameObjectsWithTag("WandarPoint");
         *
         * Transform[] waypoints = new Transform[pointList.Length];
         * int i = 0;
         * foreach(GameObject obj in pointList)
         * {
         * waypoints[i] = obj.transform;
         * i++;
         * }
         *
         * PatrolState patrol = new PatrolState(waypoints);
         *
         * patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
         * patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);
         */
/*        ChaseState chase = new ChaseState(waypoints);
 *      chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
 *      chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
 *      chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);
 *
 *      AttackState attack = new AttackState(waypoints);
 *      attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
 *      attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
 *      attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);
 *
 */

        // AddFSMState(patrol);

/*        AddFSMState(chase);
 *      AddFSMState(attack);
 *      AddFSMState(dead);*/

        SwimState              swim              = new SwimState();
        SawObstacleState       sawObstacle       = new SawObstacleState();
        TurningAwayState       turningAway       = new TurningAwayState();
        JumpState              jump              = new JumpState();
        JumpingUnderWaterState jumpingUnderWater = new JumpingUnderWaterState();
        JumpingAboveWaterState jumpingAboveWater = new JumpingAboveWaterState();
        BumpState              bump              = new BumpState();
        FallingState           falling           = new FallingState();
        HitWaterState          hitWater          = new HitWaterState();
        DeadState              dead              = new DeadState();

        AddFSMState(swim);
        AddFSMState(sawObstacle);
        AddFSMState(turningAway);
        AddFSMState(jump);
        AddFSMState(jumpingUnderWater);
        AddFSMState(jumpingAboveWater);
        AddFSMState(falling);
        AddFSMState(hitWater);
        AddFSMState(bump);
        AddFSMState(dead);

        swim.AddTransition(Transition.Tapped, FSMStateID.Jump);
        swim.AddTransition(Transition.BumpedIntoSomething, FSMStateID.Bump);
        swim.AddTransition(Transition.SawObstacle, FSMStateID.SawObstacle);
        swim.AddTransition(Transition.SwimmingToTurning, FSMStateID.TurningAway);
        swim.AddTransition(Transition.GoneBelow, FSMStateID.Dead);

        sawObstacle.AddTransition(Transition.FoundClearDirection, FSMStateID.TurningAway);
        turningAway.AddTransition(Transition.TurnIsComplete, FSMStateID.Swimming);

        jump.AddTransition(Transition.HasJumped, FSMStateID.JumpingUnderWater);

        jumpingUnderWater.AddTransition(Transition.AboveWater, FSMStateID.JumpingAboveWater);
        jumpingUnderWater.AddTransition(Transition.ReturnToSwimming, FSMStateID.Swimming);

        jumpingAboveWater.AddTransition(Transition.ReachedApex, FSMStateID.Falling);

        falling.AddTransition(Transition.AtSurface, FSMStateID.HitWater);

        hitWater.AddTransition(Transition.UnderWater, FSMStateID.JumpingUnderWater);

        bump.AddTransition(Transition.HasBumped, FSMStateID.JumpingUnderWater);

        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        dead.AddTransition(Transition.Z, FSMStateID.Swimming);

        //falling.AddTransition(Transition.GoneBelow, FSMStateID.Dead);
    }