AddTransition() публичный Метод

public AddTransition ( Transition, trans, StateID id ) : void
trans Transition,
id StateID
Результат void
    public GameStateController()
    {
        gameFsm       = new FSM("GameFSM");
        preStartState = gameFsm.AddState((byte)GameState.PreStart);
        idleState     = gameFsm.AddState((byte)GameState.Idle);
        playState     = gameFsm.AddState((byte)GameState.Play);
        pauseState    = gameFsm.AddState((byte)GameState.Pause);
        gameOverState = gameFsm.AddState((byte)GameState.GameOver);

        preStartAction = new PreStartAction(preStartState);
        playingAction  = new PlayAction(playState);
        pauseAction    = new PauseAction(pauseState);
        gameOverAction = new GameOverAction(gameOverState);
        idleAction     = new IdleAction(idleState);

        preStartState.AddTransition((byte)FSMTransition.ToIdle, idleState);
        idleState.AddTransition((byte)FSMTransition.ToPlay, playState);
        playState.AddTransition((byte)FSMTransition.ToPause, pauseState);
        playState.AddTransition((byte)FSMTransition.ToGameOver, gameOverState);
        gameOverState.AddTransition((byte)FSMTransition.ToIdle, idleState);

        preStartAction.Init();
        idleAction.Init();
        playingAction.Init();
        pauseAction.Init();
        gameOverAction.Init();
    }
    // Use this for initialization
    void Start()
    {
        FSMState waiting = new FSMState();

        waiting.enterActions.Add(StopCounting);

        FSMState angry = new FSMState();

        angry.enterActions.Add(StartCounting);
        angry.stayActions.Add(UpdateCounter);

        FSMState hit = new FSMState();

        hit.enterActions.Add(Hit);

        FSMState end = new FSMState();

        end.enterActions.Add(ToSecondStage);

        FSMTransition t1 = new FSMTransition(PlayersInRange);
        FSMTransition t2 = new FSMTransition(NoPlayersInRange);
        FSMTransition t3 = new FSMTransition(TimeOver);
        FSMTransition t4 = new FSMTransition(EnoughPlayersInRange);

        waiting.AddTransition(t1, angry);
        angry.AddTransition(t2, waiting);
        angry.AddTransition(t3, hit);
        angry.AddTransition(t4, end);
        hit.AddTransition(t2, waiting);
    }
Пример #3
0
    private void Start()
    {
        fsm = new FSM("AITest FSM Two");
        MoveForwardState = fsm.AddState("MoveForwardState");
        IdleState        = fsm.AddState("MoveRightState");
        TurnState        = fsm.AddState("TurnState");

        MoveForwardAction = new MoveAction(MoveForwardState);
        IdleAction        = new MoveAction(IdleState);
        TurnAction        = new TurnAction(TurnState);

        MoveForwardState.AddAction(MoveForwardAction);
        IdleState.AddAction(IdleAction);
        TurnState.AddAction(TurnAction);

        MoveForwardState.AddTransition("ToTurn", TurnState);

        TurnState.AddTransition("ToIdle", IdleState);
        TurnState.AddTransition("ToTurn", TurnState);

        IdleState.AddTransition("ToForward", MoveForwardState);
        IdleState.AddTransition("ToTurn", TurnState);


        MoveForwardAction.Init(this.transform, .1f, 2.0f, "ToTurn");
        TurnAction.Init(this.transform, 2.0f, "ToIdle");
        IdleAction.Init(this.transform, 0, 2.0f, "ToForward");

        fsm.Start("MoveForwardState");
    }
    // Use this for initialization
    void Start()
    {
        fsm           = new Core.FSM.FSM("PatrolDialogueNPCFSM");
        moveState     = fsm.AddState("MoveState");
        idleState     = fsm.AddState("IdleState");
        dialogueState = fsm.AddState("DialogueState");

        moveAction     = new WaypointMoveAction(moveState);
        idleAction     = new NPCIdleScoutAction(idleState);
        dialogueAction = new NPCDialogueAction(dialogueState);


        moveState.AddAction(moveAction);
        idleState.AddAction(idleAction);
        dialogueState.AddAction(dialogueAction);

        moveAction.Init(GetComponent <Rigidbody>(), gameObject.transform, movementSpeed, waypoints, "ToIdle");
        idleAction.Init(3, gameObject.transform);
        dialogueAction.Init(this, dialogueIdentifier);

        idleState.AddTransition("ToDialogue", dialogueState);
        idleState.AddTransition("ToNextWaypoint", moveState);

        moveState.AddTransition("ToIdle", idleState);
        dialogueState.AddTransition("ToIdle", idleState);

        fsm.Start("MoveState");
    }
Пример #5
0
    void Start()
    {
        formation = GetComponent <EnemyFormationManager>();

        //States
        FSMState idle = new FSMState();

        idle.enterActions.Add(GoToCamp);
        idle.stayActions.Add(Watch);
        idle.exitActions.Add(ExitIdleState);

        FSMState chase = new FSMState();

        chase.enterActions.Add(StartChase);
        chase.stayActions.Add(Chase);
        chase.exitActions.Add(StopChase);

        FSMState attack = new FSMState();

        attack.enterActions.Add(StartAttack);
        attack.stayActions.Add(Fight);
        attack.exitActions.Add(StopAttack);

        FSMState dead = new FSMState();

        dead.enterActions.Add(Dead);

        FSMState returnInPosition = new FSMState();

        returnInPosition.enterActions.Add(ReturnToPosition);
        returnInPosition.stayActions.Add(Returning);
        returnInPosition.exitActions.Add(StopReturning);

        //Transitions
        FSMTransition t1 = new FSMTransition(ScanField);
        FSMTransition t2 = new FSMTransition(ScanFieldMoreNear);
        FSMTransition t3 = new FSMTransition(OutOfAttackRange);
        FSMTransition t4 = new FSMTransition(OutOfMaximumDistance);
        FSMTransition t5 = new FSMTransition(NoEnemiesInRange);
        FSMTransition t6 = new FSMTransition(NearEnemy);
        FSMTransition t7 = new FSMTransition(IsDead);
        FSMTransition t8 = new FSMTransition(InitialPosition);

        // Link states with transitions
        idle.AddTransition(t1, chase);
        chase.AddTransition(t2, attack);
        attack.AddTransition(t3, chase);
        chase.AddTransition(t4, returnInPosition);
        attack.AddTransition(t5, returnInPosition);
        returnInPosition.AddTransition(t6, attack);
        attack.AddTransition(t7, dead);
        returnInPosition.AddTransition(t8, idle);

        // Setup a FSA at initial state
        fsm = new FSM(idle);

        // Start monitoring
        StartCoroutine(Patrol());
    }
Пример #6
0
    void Start()
    {
        rb = GetComponent <Rigidbody>();
        if (!BallBody)
        {
            return;
        }

        RedPos  = GameObject.Find("RedGoal").GetComponent <Rigidbody>().position;
        BluePos = GameObject.Find("BlueGoal").GetComponent <Rigidbody>().position;
        allies  = GameObject.FindGameObjectsWithTag("RedPlayer");
        enemies = GameObject.FindGameObjectsWithTag("BluePlayer");
        //each player can be average or skilled, setting dribble chance at 50% (meh) or 67% (literally Messi)
        Skill = Rand.Next(1) + 3;

        FSMState Advance = new FSMState();

        //Advance.enterActions.Add(BringBallAhead);
        Advance.stayActions.Add(BringBallAhead);
        Advance.stayActions.Add(TryDribble);
        Advance.stayActions.Add(HardDribble);
        Advance.stayActions.Add(ShootBall);
        Advance.stayActions.Add(PassTheBall);

        FSMState SupportAdv = new FSMState();

        SupportAdv.stayActions.Add(ReachPosition);

        FSMState Backing = new FSMState();

        Backing.stayActions.Add(RetreatToGoal);

        FSMState Chase = new FSMState();

        Chase.stayActions.Add(ChaseBall);
        Chase.stayActions.Add(SpeedRun);

        FSMTransition t1 = new FSMTransition(BallControl);
        FSMTransition t2 = new FSMTransition(BallToMate);
        FSMTransition t3 = new FSMTransition(EnemyBall);
        FSMTransition t4 = new FSMTransition(BallInSight);
        FSMTransition t5 = new FSMTransition(BallNotInSight);

        Advance.AddTransition(t2, SupportAdv);
        Advance.AddTransition(t3, Chase);
        SupportAdv.AddTransition(t1, Advance);
        SupportAdv.AddTransition(t3, Backing);
        Chase.AddTransition(t1, Advance);
        Chase.AddTransition(t5, Backing);
        Chase.AddTransition(t2, SupportAdv);
        Backing.AddTransition(t4, Chase);
        Backing.AddTransition(t2, SupportAdv);

        fsm = new FSM(Chase);
        StartCoroutine(Play());
    }
Пример #7
0
    void Awake()
    {
        if (target == null)
        {
            target = FindObjectOfType <PlayerController>().gameObject;
        }
        stadardSpeed = GetComponent <Pathfinding.AIPath>().maxSpeed;

        GameManager = GameObject.FindObjectOfType <GlobalGameManager>();
        // Define states and link actions when enter/exit/stay
        FSMState wander  = new FSMState(); //off
        FSMState stunned = new FSMState(); //off
        FSMState seek    = new FSMState(); //alarm

        wander.enterActions.Add(StartWander);
        stunned.enterActions.Add(StartStunned);
        stunned.stayActions.Add(BeStunned);
        wander.stayActions.Add(WanderAround);
        seek.enterActions.Add(Boost);
        seek.stayActions.Add(RingAlarm);

        // Define transitions
        FSMTransition startSeek    = new FSMTransition(EnemiesAround);
        FSMTransition startStunned = new FSMTransition(GetHit);
        FSMTransition stopStunned  = new FSMTransition(GetFree);
        FSMTransition returnWander = new FSMTransition(NoEnemiesAround);


        // Link states with transitions
        wander.AddTransition(startSeek, seek);
        wander.AddTransition(startStunned, stunned);
        seek.AddTransition(startStunned, stunned);
        seek.AddTransition(returnWander, wander);
        stunned.AddTransition(stopStunned, wander);

        if (Generator != null)
        {
            FSMState fixGenerator = new FSMState(); //alarm

            fixGenerator.stayActions.Add(Fix);

            FSMTransition goFix     = new FSMTransition(isGeneratorBroken);
            FSMTransition endFixing = new FSMTransition(isGeneratorFixed);

            wander.AddTransition(goFix, fixGenerator);
            fixGenerator.AddTransition(startSeek, seek);
            fixGenerator.AddTransition(endFixing, wander);
        }
        // Setup a FSA at initial state
        fsm = new FSM(wander);

        // Start monitoring
        StartCoroutine(Patrol());
    }
Пример #8
0
    // Start is called before the first frame update
    void Awake()
    {
        damage       = enemyPreset.damage;
        moveTime     = enemyPreset.moveTime;
        idleTimeMin  = enemyPreset.idleTimeMin;
        idleTimeMax  = enemyPreset.idleTimeMax;
        wanderRadius = enemyPreset.wanderRadius;

        home = transform.position;

        trigger = GetComponentInChildren <DetectPlayer>();

        trigger.GetComponent <SphereCollider>().radius = enemyPreset.detectionRadius;

        navMeshAgent = GetComponent <NavMeshAgent>();

        navMeshAgent.speed = enemyPreset.speed;

        fsm = new FSM("MeleeAI FSM");

        WanderState = fsm.AddState("WanderState");
        IdleState   = fsm.AddState("IdleState");
        AlertState  = fsm.AddState("AlertState");
        MeleeState  = fsm.AddState("MeleeState");

        WanderAction = new WanderAction(WanderState);
        IdleAction   = new TextAction(IdleState);
        alertAction  = new AlertAction(AlertState);
        meleeAction  = new MeleeAction(MeleeState);

        WanderState.AddAction(WanderAction);
        IdleState.AddAction(IdleAction);
        AlertState.AddAction(alertAction);
        MeleeState.AddAction(meleeAction);

        WanderState.AddTransition("ToIdle", IdleState);
        WanderState.AddTransition("PlayerDetect", AlertState);
        IdleState.AddTransition("ToWander", WanderState);
        IdleState.AddTransition("PlayerDetect", AlertState);

        AlertState.AddTransition("ToIdle", IdleState);
        AlertState.AddTransition("ToMelee", MeleeState);
        MeleeState.AddTransition("ToAlert", AlertState);

        WanderAction.Init(this.transform, home, navMeshAgent, wanderRadius, moveTime, "ToIdle");
        IdleAction.Init("Idling", Random.Range(idleTimeMin, idleTimeMax), "ToWander");

        alertAction.Init(trigger, navMeshAgent, "ToIdle");
        meleeAction.Init(this.transform, damage, trigger, FindObjectOfType <PlayerManager>(), "ToAlert");

        fsm.Start("IdleState");
    }
Пример #9
0
    // Use this for initialization
    void Start()
    {
        player        = GameObject.FindGameObjectWithTag("Players");
        monsterAnim   = monsterObject.GetComponent <Animation> ();
        monsterWander = GetComponent <MonsterWandering> ();


        //FiniteStateMachine for Monsters
        fsm = new FSM("Monsters-FSM-AI");
        //define State and Action
        idleState    = fsm.AddState("IdleState");
        idleAction   = new actionIdle(idleState);
        wanderState  = fsm.AddState("WanderState");
        wanderAction = new actionWander(wanderState);
        chaseState   = fsm.AddState("ChaseState");
        chaseAction  = new actionChase(chaseState);
        backState    = fsm.AddState("BackState");
        backAction   = new actionBack(backState);
        sleepState   = fsm.AddState("SleepState");
        sleepAction  = new actionSleep(sleepState);

        //Add Action to State
        idleState.AddAction(idleAction);
        wanderState.AddAction(wanderAction);
        chaseState.AddAction(chaseAction);
        backState.AddAction(backAction);
        sleepState.AddAction(sleepAction);


        //Add Transation
        idleState.AddTransition("ToWander", wanderState);
        idleState.AddTransition("ToSleep", sleepState);
        wanderState.AddTransition("ToBack", backState);
        wanderState.AddTransition("ToChase", chaseState);
        chaseState.AddTransition("ToWander", wanderState);
        backState.AddTransition("ToSleep", sleepState);
        sleepState.AddTransition("ToIdle", idleState);

        //Init Action
        wanderAction.Init(gameObject, player, monsterAnim, monsterWander, "ToChase");
        idleAction.Init(gameObject, player, monsterAnim, monsterWander, "ToWander");
        chaseAction.Init(gameObject, player, monsterAnim, monsterWander, "ToWander");
        backAction.Init(gameObject, player, monsterAnim, monsterWander, "ToSleep");
        sleepAction.Init(gameObject, player, monsterAnim, monsterWander, "ToIdle");

        //Start
        fsm.Start("SleepState");
    }
Пример #10
0
    // Use this for initialization
    void Start()
    {
        anim     = GetComponent <Animator>();
        movAgent = GetComponent <UnityEngine.AI.NavMeshAgent>();

        CurrentDestination = new Vector3(20, 0, 20);
        CurrentTarget      = null;
        CurrentState       = RoosterStates.ROAMING;

        FSMState Roaming = new FSMState();

        Roaming.stayActions.Add(RoamingState);

        FSMState Chasing = new FSMState();

        Chasing.stayActions.Add(ChasingState);

        FSMState Resetting = new FSMState();

        Resetting.stayActions.Add(ResettingState);

        FSMState Vulnerable = new FSMState();

        Vulnerable.stayActions.Add(VulnerableState);

        FSMTransition TransitionEnemyInFOW         = new FSMTransition(EnemyInFOW);
        FSMTransition TransitionEnemyOutOfSight    = new FSMTransition(EnemyOutOfSight);
        FSMTransition TransitionEnemyInAttackRange = new FSMTransition(EnemyInAttackRange);
        FSMTransition TransitionRemoveALife        = new FSMTransition(RemoveALife);
        FSMTransition TransitionReset          = new FSMTransition(Reset);
        FSMTransition TransitionEndedReset     = new FSMTransition(EndedReset);
        FSMTransition TransitionTrapped        = new FSMTransition(InTrappedState);
        FSMTransition TransitionTriggeredAlarm = new FSMTransition(TriggeredAlarm);

        Roaming.AddTransition(TransitionEnemyInFOW, Chasing);
        Roaming.AddTransition(TransitionTrapped, Vulnerable);
        Chasing.AddTransition(TransitionEnemyOutOfSight, Roaming);
        Chasing.AddTransition(TransitionEnemyInAttackRange, Roaming);
        Chasing.AddTransition(TransitionTrapped, Vulnerable);
        Chasing.AddTransition(TransitionTriggeredAlarm, Roaming);
        Vulnerable.AddTransition(TransitionRemoveALife, Resetting);
        Vulnerable.AddTransition(TransitionReset, Resetting);
        Resetting.AddTransition(TransitionEndedReset, Roaming);

        fsm = new FSM(Roaming);

        ResetTimers();
    }
Пример #11
0
        private void Start()
        {
            fsm          = new FiniteStateMachine("AITest FSM");
            IdleState    = fsm.AddState("IdleState");
            ScanState    = fsm.AddState("ScanState");
            PatrolState  = fsm.AddState("WanderState");
            PatrolAction = new WanderAction(PatrolState);
            IdleAction   = new IdleAction(IdleState);
            ScanAction   = new ScanningAction(ScanState);
            deathState   = fsm.AddState("DeathState");
            DeathAction  = new DeathState(deathState);
            //This adds the actions to the state and add state to it's transition map
            PatrolState.AddAction(PatrolAction);
            IdleState.AddAction(IdleAction);

            PatrolState.AddTransition("ToIdle", IdleState);
            IdleState.AddTransition("ToPatrol", PatrolState);
            ScanState.AddTransition("ToScanning", ScanState);
            deathState.AddTransition("ToDeath", deathState);
            PatrolAction.Init(target, 3.0f, gameObject.GetComponent <EnemyAstar>(), "ToIdle");
            IdleAction.Init(target, "AI on Idle", 3.0f, gameObject.GetComponent <EnemyAstar>(), "ToPatrol");
            DeathAction.Init(3.0f, gameObject.GetComponent <EnemyAstar>());
            ScanAction.Init(3.0f);
            fsm.StartMachine("IdleState");
        }
Пример #12
0
        private void Start()
        {
            BtAction executeTactic = new BtAction(ExecuteTactic);
            BtAction ability       = new BtAction(() => _activeAbility != null);
            BtAction allInPosition = new BtAction(() =>
                                                  !_activeAbility.GetData().InPositionBeforeActivation ||
                                                  _groupManager.Imps.All(pair => pair.Key.GetComponent <ContextGroupFormation>().InPosition()));
            BtAction doAbility = new BtAction(ExecuteAbility);

            BtSequence combatSequence =
                new BtSequence(new IBtTask[] { executeTactic, ability, allInPosition, doAbility });

            FSMState outOfCombat = new FSMState();
            FSMState inCombat    = new FSMState();

            FSMTransition battleEnter = new FSMTransition(() => _inBattle);
            FSMTransition battleExit  = new FSMTransition(() => !_inBattle);

            outOfCombat.AddTransition(battleEnter, inCombat);
            inCombat.AddTransition(battleExit, outOfCombat);

            inCombat.enterActions.Add(() => OnTacticChanged?.Invoke(_activeTactic));
            inCombat.stayActions.Add(() => combatSequence.Run());

            outOfCombat.stayActions.Add(SetPlayer);

            FSM groupFsm = new FSM(outOfCombat);

            StartCoroutine(FsmStayAlive(groupFsm));
        }
Пример #13
0
    void Start()
    {
        //States
        FSMState patrol = new FSMState();

        patrol.enterActions.Add(SetGoal);
        patrol.stayActions.Add(Walk);
        patrol.exitActions.Add(StopPatrol);

        FSMState attack = new FSMState();

        attack.enterActions.Add(StartAttack);
        attack.stayActions.Add(Fight);
        attack.exitActions.Add(StopAttack);

        //Transitions
        FSMTransition t1 = new FSMTransition(ScanField);
        FSMTransition t2 = new FSMTransition(Attack);

        // Link states with transitions
        patrol.AddTransition(t1, attack);
        attack.AddTransition(t2, patrol);

        // Setup a FSA at initial state
        fsm = new FSM(patrol);

        // Start monitoring
        StartCoroutine(Patrol());
    }
    /// <summary>
    ///  Create each state switch to the given state's transition ,and add them to the transition list.
    /// </summary>
    /// <param name="nextFsmStateName">the state which them will switch to</param>
    /// <param name="fsmTransitionConditionArray">Some transition conditions</param>
    public void CreateAnyFSMStateToFSMStateTransition(string nextFsmStateName, IFSMTransitionCondition[] fsmTransitionConditionArray)
    {
        string nextFSMStateNameHash = HashTool.StringToHash(nextFsmStateName);

        FSMState nextFSMState = null;

        bool nextFSMStateExist = m_FSMStateDic.TryGetValue(nextFSMStateNameHash, out nextFSMState);

        if (nextFSMStateExist == false)
        {
            Debug.LogErrorFormat("The nextFSMStateName:{0} is not exist", nextFsmStateName);

            return;
        }


        foreach (KeyValuePair <string, FSMState> kv in m_FSMStateDic)
        {
            FSMState fsmState = kv.Value;

            if (fsmState != m_Entry &&
                fsmState != m_Exit &&
                fsmState != m_EndFSMState &&
                fsmState != nextFSMState)
            {
                fsmState.AddTransition(nextFSMState, fsmTransitionConditionArray);
            }
        }
    }
    /// <summary>
    /// Create a transition which represent the state switch to another state,and add it to the transition list.
    /// </summary>
    /// <param name="fsmStateName">The state name</param>
    /// <param name="nextFSMStateName">The name of the next state</param>
    /// <param name="fsmTransitionConditionArray">Some transition conditions</param>
    public FSMTransition CreateFSMStateToAnotherFSMStateTransition(string fsmStateName, string nextFSMStateName, IFSMTransitionCondition[] fsmTransitionConditionArray)
    {
        //convert the state name to hash value,to improve performance
        string fsmStateNameHash = HashTool.StringToHash(fsmStateName);

        FSMState fsmState = null;

        bool fsmStateExist = m_FSMStateDic.TryGetValue(fsmStateNameHash, out fsmState);

        if (fsmStateExist == false)
        {
            Debug.LogErrorFormat("The fsmStateName:{0} is not exist", fsmStateName);

            return(null);
        }

        //convert the state name to hash value,to improve performance
        string nextFSMStateNameHash = HashTool.StringToHash(nextFSMStateName);

        FSMState nextFSMState = null;

        bool nextFSMStateExist = m_FSMStateDic.TryGetValue(nextFSMStateNameHash, out nextFSMState);

        if (nextFSMStateExist == false)
        {
            Debug.LogErrorFormat("The nextFSMStateName:{0} is not exist", nextFSMStateName);

            return(null);
        }

        return(fsmState.AddTransition(nextFSMState, fsmTransitionConditionArray));
    }
Пример #16
0
    // Use this for initialization
    void Start()
    {
        fsm                 = new FSM("AITest FSM Two");
        MoveLeftState       = fsm.AddState("MoveLeftState");
        MoveRightState      = fsm.AddState("MoveRightState");
        MoveLeftAction      = new MoveAction(MoveLeftState);
        MoveRightAction     = new MoveAction(MoveRightState);
        MoveLeftTextAction  = new TextAction(MoveLeftState);
        MoveRightTextAction = new TextAction(MoveRightState);

        //This adds the actions to the state and add state to it's transition map
        MoveLeftState.AddAction(MoveLeftTextAction);
        MoveLeftState.AddAction(MoveLeftAction);
        MoveRightState.AddAction(MoveRightTextAction);
        MoveRightState.AddAction(MoveRightAction);

        MoveLeftState.AddTransition("ToRight", MoveRightState);
        MoveRightState.AddTransition("ToLeft", MoveLeftState);

        //this initializes the actions
        MoveLeftTextAction.Init("AI Moving Left", 1f, "");
        MoveRightTextAction.Init("AI Moving Right", 1f, "");
        MoveLeftAction.Init(this.transform, new Vector3(1, 0, 0), new Vector3(-1, 0, 0), 1.0f, "ToRight");
        MoveRightAction.Init(this.transform, new Vector3(-1, 0, 0), new Vector3(1, 0, 0), 1.0f, "ToLeft");

        //Starts the FSM
        fsm.Start("MoveLeftState");
    }
Пример #17
0
    void Start()
    {
        // Define states and link actions when enter/exit/stay
        FSMState patrol = new FSMState();

        FSMState stayAway = new FSMState();

        patrol.enterActions.Add(StartAlarm);
        patrol.stayActions.Add(StayAlarm);
        patrol.exitActions.Add(ShutAlarm);

        stayAway.enterActions.Add(StartPause);
        stayAway.stayActions.Add(StayPause);
        stayAway.exitActions.Add(ShutPause);

        // Define transitions
        FSMTransition t1 = new FSMTransition(FlockTouched);
        FSMTransition t2 = new FSMTransition(PauseEspired);

        // Link states with transitions
        stayAway.AddTransition(t2, patrol);
        patrol.AddTransition(t1, stayAway);

        // Setup a FSA at initial state
        fsm = new FSM(stayAway);

        // Start monitoring
        StartCoroutine(Patrol());
    }
Пример #18
0
    void Start()
    {
        if (!ambientLight)
        {
            return;                             // Sanity
        }
        // Define states and link actions when enter/exit/stay
        FSMState off = new FSMState();

        FSMState alarm = new FSMState();

        alarm.enterActions.Add(StartAlarm);
        alarm.stayActions.Add(RingAlarm);
        alarm.exitActions.Add(ShutAlarm);

        // Define transitions
        FSMTransition t1 = new FSMTransition(EnemiesAround);
        FSMTransition t2 = new FSMTransition(NoEnemiesAround);

        // Link states with transitions
        off.AddTransition(t1, alarm);
        alarm.AddTransition(t2, off);

        // Setup a FSA at initial state
        fsm = new FSM(off);

        // Start monitoring
        StartCoroutine(Patrol());
    }
Пример #19
0
    // Use this for initialization
    void Start()
    {
        m_fsm = new FSM();
        FSMState  state1  = new FSMState("log", m_fsm, true);
        LogAction action1 = new LogAction();

        action1.SetOwner(state1);
        state1.AddAction(action1);
        state1.AddTransition("calc", 2);

        FSMState   state2  = new FSMState("calc", m_fsm);
        CalcAction action2 = new CalcAction();

        action2.SetOwner(state2);
        state2.AddAction(action2);
        state2.AddTransition("log", state1.id);

        m_fsm.AddTransition("g_calc", state2.id);
        m_fsm.AddTransition("g_log", state1.id);

        m_fsm.AddState(state1);
        m_fsm.AddState(state2);

        m_fsm.Initialize();
        m_fsm.EnableFSM();

        StartCoroutine(SendGlobalEvent());
    }
Пример #20
0
    //Add a transition to the most recently created state.
    //Transistion is created with at least one expression.
    protected void AddTransistion(string nextState, Condition condition, float param, bool truth)
    {
        FSMTransition transition = new FSMTransition(nextState);

        latestTransition = transition;
        latestTransition.AddExpression(condition, param, truth);
        latestState.AddTransition(transition);
    }
Пример #21
0
    // Start is called before the first frame update
    void Start()
    {
        fsm         = new FSM("Test Ai");
        testState1  = fsm.AddState("testState1");
        testState2  = fsm.AddState("testState2");
        testState3  = fsm.AddState("testState3");
        testAction1 = new TestAction1(testState1);
        testAction2 = new TestAction1(testState2);
        testAction3 = new TestAction1(testState3);

        finishEvent1 = new List <string>
        {
            "To 2",
            "To 3"
        };
        finishEvent2 = new List <string>
        {
            "To 1",
        };
        finishEvent3 = new List <string>
        {
            "To 1",
        };

        testState1.AddAction(testAction1);
        testState2.AddAction(testAction2);
        testState3.AddAction(testAction3);


        testState1.AddTransition("To 2", testState2);
        testState1.AddTransition("To 3", testState3);

        testState2.AddTransition("To 1", testState1);
        testState3.AddTransition("To 1", testState1);

        testAction1.init("test 1", 1f, finishEvent1);
        testAction2.init("test 2", 1f, finishEvent2);
        testAction3.init("test 3", 1f, finishEvent3);
        fsm.Start("testState1");
    }
Пример #22
0
    void Start()
    {
        turret         = GetComponent <TurretBehaviour>();
        viewFromGround = new Vector3(transform.position.x, 0f, transform.position.z); //for overlap spheres

        //States
        FSMState idle = new FSMState();

        idle.enterActions.Add(Wait);

        FSMState active = new FSMState();

        active.enterActions.Add(Alerted);
        active.exitActions.Add(StopAlert);

        FSMState attack = new FSMState();

        attack.enterActions.Add(StartAttack);
        attack.stayActions.Add(Attack);
        attack.exitActions.Add(StopAttack);

        //Transitions
        FSMTransition t1 = new FSMTransition(PatrolInCamp);
        FSMTransition t2 = new FSMTransition(NobodyOnAlarm);
        FSMTransition t3 = new FSMTransition(EnemiesInRange);
        FSMTransition t4 = new FSMTransition(NoEnemiesInRange);

        // Link states with transitions
        idle.AddTransition(t1, active);
        active.AddTransition(t2, idle);
        active.AddTransition(t3, attack);
        attack.AddTransition(t4, active);

        //Setup a FSA at initial state
        fsm = new FSM(idle);

        // Start monitoring
        StartCoroutine(Patrol());
    }
Пример #23
0
    // Use this for initialization
    void Start()
    {
        anim = GetComponent <Animator>();

        playerTags.Add("Bean");
        playerTags.Add("Eal");
        playerTags.Add("Loin");
        playerTags.Add("Sage");

        FSMState waiting = new FSMState();

        waiting.enterActions.Add(StopCounting);

        FSMState angry = new FSMState();

        angry.enterActions.Add(StartCounting);
        angry.stayActions.Add(UpdateCounter);

        FSMState hit = new FSMState();

        hit.enterActions.Add(Hit);

        FSMState end = new FSMState();

        end.enterActions.Add(ToSecondStage);

        FSMTransition t1 = new FSMTransition(PlayersInRange);
        FSMTransition t2 = new FSMTransition(NoPlayersInRange);
        FSMTransition t3 = new FSMTransition(TimeOver);
        FSMTransition t4 = new FSMTransition(EnoughPlayersInRange);

        waiting.AddTransition(t1, angry);
        angry.AddTransition(t2, waiting);
        angry.AddTransition(t3, hit);
        angry.AddTransition(t4, end);
        hit.AddTransition(t2, waiting);

        fsm = new FSM(waiting);
    }
Пример #24
0
    void Start()
    {
        fSMSystem = new FSMSystem();

        fSMState = new Example_Start(fSMSystem);
        fSMState.AddTransition(Transition.RuningTrans, StateID.Runing);
        fSMSystem.AddState(fSMState);

        fSMState = new Example_Runing(fSMSystem);
        fSMState.AddTransition(Transition.StartTrans, StateID.Start);
        fSMSystem.AddState(fSMState);

        fSMSystem.Start();
    }
    /// <summary>
    /// The Initialize function before the finite state machine system running
    /// </summary>
    public void OnInitialize()
    {
        m_Entry = new FSMEntry("FSMEntry");

        IFSMTransitionCondition[] entryFSMTransitionConditionArray = new IFSMTransitionCondition[1] {
            new FSMDefaultTransitionCondition()
        };

        m_Entry.AddTransition(m_DefaultFSMState, entryFSMTransitionConditionArray);

        AddState(m_Entry);

        this.m_CurrentFSMState = m_Entry;
    }
Пример #26
0
    void StartFSM()
    {
        // Define states and link actions when enter/exit/stay
        FSMState idleAction = new FSMState {
            enterActions = new FSMAction[] { Idle }
        };

        FSMState moveAction = new FSMState {
            enterActions = new FSMAction[] { Move }
        };

        FSMState seekAction = new FSMState {
            enterActions = new FSMAction[] { FindPosition }
        };

        // Define transitions
        FSMTransition fromIdleToMove = new FSMTransition(CheckTimeToMove);
        FSMTransition fromMoveToIdle = new FSMTransition(CheckRechedPosition);
        FSMTransition fromIdleToSeek = new FSMTransition(CheckNearObject);
        FSMTransition fromSeekToIdle = new FSMTransition(CheckReachedObject);
        FSMTransition fromMoveToSeek = new FSMTransition(CheckNearObject);

        // Link states with transitions
        idleAction.AddTransition(fromIdleToMove, moveAction);
        idleAction.AddTransition(fromIdleToSeek, seekAction);
        moveAction.AddTransition(fromMoveToIdle, idleAction);
        moveAction.AddTransition(fromMoveToSeek, seekAction);
        seekAction.AddTransition(fromSeekToIdle, idleAction);

        // Setup a FSA at initial state
        fsmMachine   = new FSM(idleAction);
        nextPosition = points[currentPos];
        isFSMStarted = true;
        // Start monitoring
        StartCoroutine("PatrolFSM");
    }
Пример #27
0
    // Use this for initialization
    void Start()
    {
        fsm        = new Core.FSM.FSM("PatrolNPCFSM");
        moveState  = fsm.AddState("MoveState");
        idleState  = fsm.AddState("IdleState");
        moveAction = new WaypointMoveAction(moveState);
        idleAction = new NPCIdleAction(idleState);

        moveState.AddAction(moveAction);
        idleState.AddAction(idleAction);

        moveAction.Init(GetComponent <Rigidbody>(), gameObject.transform, movementSpeed, waypoints, "ToIdle");
        idleAction.Init();

        idleState.AddTransition("ToNextWaypoint", moveState);
        moveState.AddTransition("ToIdle", idleState);

        fsm.Start("IdleState");
    }
Пример #28
0
    private void Start()
    {
        fsm          = new FSM("AITest FSM");
        IdleState    = fsm.AddState("IdleState");
        PatrolState  = fsm.AddState("PatrolState");
        PatrolAction = new TextAction(PatrolState);
        IdleAction   = new TextAction(IdleState);

        PatrolState.AddAction(PatrolAction);
        IdleState.AddAction(IdleAction);

        PatrolState.AddTransition("ToIdle", IdleState);
        IdleState.AddTransition("ToPatrol", PatrolState);

        PatrolAction.Init("AI on patrol", 3f, "ToIdle");
        IdleAction.Init("AI on idle", 2f, "ToPatrol");

        fsm.Start("IdleState");
    }
Пример #29
0
    private void Start()
    {
        fsm          = new FSM("AITest FSM");
        idleState    = fsm.AddState("IdleState");
        patrolState  = fsm.AddState("PatrolState");
        idleAction   = new TextAction(idleState);
        patrolAction = new TextAction(patrolState);

        //This adds the actions to the state and add state to it's transition map
        patrolState.AddAction(patrolAction);
        idleState.AddAction(idleAction);

        patrolState.AddTransition("ToIdle", idleState);
        idleState.AddTransition("ToPatrol", patrolState);

        patrolAction.Init("AI on Patrol", 3.0f, "ToIdle");
        idleAction.Init("AI on Idle", 2.0f, "ToPatrol");

        fsm.Start("IdleState");
    }
Пример #30
0
    private void Start()
    {
        fsm         = new FSM("Cub AI");
        FleeState   = fsm.AddState("FleeState");
        FollowState = fsm.AddState("FollowState");

        FleeAction   = new FleeAction(FleeState);
        FollowAction = new FollowAction(FollowState);

        FollowState.AddAction(FollowAction);
        FleeState.AddAction(FleeAction);

        FollowState.AddTransition("ToFlee", FleeState);
        FleeState.AddTransition("ToFollow", FollowState);

        FollowAction.Init(this.transform, .1f, gameObject);
        FleeAction.Init(this.transform, .1f, gameObject);

        fsm.Start("FollowState");
    }