示例#1
0
    private void MakeFSM()
    {
        mFSMSystem = new FSMSystem();

        FSMState standbyState = new StateStandby(mFSMSystem);

        ///standbyState StateID.StandbyState,转换条件分别为
        ///Transition.SeeEnemy
        standbyState.AddTransition(Transition.SeeEnemy, StateID.ChaseState);

        FSMState chaseState = new StateChase(mFSMSystem);

        ///由ChaseState状态可以转换到 StateID.StandbyState StateID.AttackState,转换条件分别为
        ///Transition.DonotSeeEnemy  Transition.EnemyInTheAttackRange
        chaseState.AddTransition(Transition.DonotSeeEnemy, StateID.StandbyState);
        chaseState.AddTransition(Transition.EnemyInTheAttackRange, StateID.AttackState);

        FSMState attackState = new StateAttack(mFSMSystem);

        ///由attackState状态可以转换到 StateID.StandbyState StateID.ChaseState,转换条件分别为
        ///Transition.DonotSeeEnemy  Transition.EnemyOutOfTheAttackRange
        attackState.AddTransition(Transition.DonotSeeEnemy, StateID.StandbyState);
        attackState.AddTransition(Transition.EnemyOutOfTheAttackRange, StateID.ChaseState);

        mFSMSystem.AddState(standbyState);
        mFSMSystem.AddState(chaseState);
        mFSMSystem.AddState(attackState);
    }
示例#2
0
    /// <summary>
    /// Initialize the character
    /// </summary>
    new public virtual void Start()
    {
        moveStick      = new ControlStick();
        jumpAlarm      = ScriptableObject.CreateInstance <Alarm>();
        hitLagAlarm    = ScriptableObject.CreateInstance <Alarm>();
        spriteRenderer = this.gameObject.GetComponentInChildren <SpriteRenderer>();

        timer     = 0;
        velocity  = new Vector3(0f, 0f, 0f);
        position  = new Vector2(0f, 0f);
        knockback = new Vector3(0f, 0f, 0f);
        jumpCount = 0;

        // Pool the states
        currentState = new StateIdle(this);
        stateAttack  = new StateAttack(this);
        stateCrouch  = new StateCrouch(this);
        stateIdle    = new StateIdle(this);
        stateDash    = new StateDash(this);
        stateJump    = new StateJump(this);
        stateRun     = new StateRun(this);
        stateHurt    = new StateHurt(this);
        stateFall    = new StateFall(this);
        playerContactFilter.layerMask = playerMask;

        timerSpeed = 1;

        canJump   = true;
        canAttack = true;
    }
示例#3
0
    void Start()
    {
        _type     = UnitType.Enemy;
        _isMoving = false;
        InitAbility();

        _players       = new List <PlayerBehaviour>();
        _playerObjects = GameObject.FindGameObjectsWithTag("Player");
        foreach (var player in _playerObjects)
        {
            _players.Add(player.GetComponent <PlayerBehaviour>());
        }

        _animator = GetComponent <Animator>();

        _stateProcessor = new StateProcessor();
        StateIdle       = new StateIdle();      //待機状態
        StateSelect     = new StateSelect();    //選択状態
        StateMove       = new StateMove();      //移動状態
        StateAttack     = new StateAttack();    //攻撃状態
        StateIntercept  = new StateIntercept(); //傍受状態

        _stateProcessor.State       = StateIdle;
        StateIdle.execDelegate      = IdleUpdate;
        StateSelect.execDelegate    = SelectUpdate;
        StateMove.execDelegate      = MoveUpdate;
        StateAttack.execDelegate    = AttackUpdate;
        StateIntercept.execDelegate = InterceptUpdate;
    }
示例#4
0
    private StateAttack _stateAttack;//自动追击
    //private _stateBack;

    public void Init(Creature owner)
    {
        _machine   = new StateMachine();
        _owner     = owner;
        _stateIdle = new StateIdle();
        _stateIdle.Init(_owner, _machine);
        _stateAttack = new StateAttack();
        _stateAttack.Init(_owner, _machine);

        _machine.RegisterState(IDLE_NAME, _stateIdle);
        _machine.RegisterState(ATTACK_NAME, _stateAttack);
        _machine.SetDefaultState(IDLE_NAME);
    }
示例#5
0
        public Enemy()
        {
            sightRadius = 100f;

            //Init states
            idle   = new StateIdle(this);
            chase  = new StateChase(this);
            attack = new StateAttack(this);

            //Linking states NB: questo è brutto
            idle.Chase   = chase;
            chase.Idle   = idle;
            chase.Attack = attack;
            attack.Idle  = idle;
            attack.Chase = chase;

            //Turn on the FSM and set currentstate to idle
            idle.OnStateEnter();
            currentState = idle;
        }
    public override void setupState(StateBehaviour state)
    {
        if (state is StateHunt)
        {
            StateHunt stateEat = (StateHunt)state;

            stateEat.prey           = this.currentPrey;
            stateEat.attackDistance = this.attackDistance;
        }
        else if (state is StateAttack)
        {
            StateAttack stateAttack = (StateAttack)state;

            stateAttack.damage = this.damage;
        }
        else
        {
            throw new System.Exception("Can't setup the state : " + state.ToString());
        }
    }
示例#7
0
    public override void Update()
    {
        // start chasing the player
        agent.SetDestination(player.position);

        // check if AI character has finished setting a path to player
        if (agent.hasPath)
        {
            // check if AI is within attack range of player, then move to Attack state
            if (CanAttackPlayer())
            {
                nextState = new StateAttack(npc, agent, anim, player);
                stage     = EVENT.EXIT;
            }
            // if AI lost sight of the player, then exit pursue stat and go Idle
            else if (!CanSeePlayer())
            {
                nextState = new StateIdle(npc, agent, anim, player);
                stage     = EVENT.EXIT;
            }
        }
    }
示例#8
0
    void Start()
    {
        _type = UnitType.Player;

        _animator  = GetComponent <Animator>();
        _menuPanel = GameObject.FindGameObjectWithTag("Panel");
        _menuFlag  = false;

        InitAbility();

        _stateProcessor = new StateProcessor();
        StateIdle       = new StateIdle();      //待機状態
        StateSelect     = new StateSelect();    //選択状態
        StateMove       = new StateMove();      //移動状態
        StateAttack     = new StateAttack();    //攻撃状態
        StateIntercept  = new StateIntercept(); //傍受状態

        _stateProcessor.State       = StateIdle;
        StateIdle.execDelegate      = IdleUpdate;
        StateSelect.execDelegate    = SelectUpdate;
        StateMove.execDelegate      = MoveUpdate;
        StateAttack.execDelegate    = AttackUpdate;
        StateIntercept.execDelegate = InterceptUpdate;
    }
示例#9
0
	public virtual StateAttack Attack(){
		StateAttack state = new StateAttack (this);
		StateContext.SetState (state);
		return state;
	}