Esempio n. 1
0
    public void Init(GameObject monsters, GameObject players, Animation monsterAnim, MonsterWandering monsterWander, string finishEvent)
    {
        this.monsters      = monsters;
        this.players       = players;
        this.monsterAnim   = monsterAnim;
        this.monsterWander = monsterWander;

        this.finishEvent = finishEvent;
    }
    public void Init(GameObject monsters, GameObject players, Animation monsterAnim, MonsterWandering monsterWander, string finishEvent)
    {
        this.monsters      = monsters;
        this.players       = players;
        this.monsterAnim   = monsterAnim;
        this.monsterWander = monsterWander;

        this.finishEvent = finishEvent;
        startPosition    = new Vector3(108.2f, 4f, 8.4f);
    }
    // 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");
    }