示例#1
0
文件: RunState.cs 项目: zzhehe/3DDemo
    public override void TriggerEvent(FsmSystem fsmSystem, GameObject gameObject)
    {
        Player player = gameObject.GetComponent <Player>();

        if (Input.GetKeyDown(KeyCode.Space))
        {
            fsmSystem.IsCanChange = true;
            fsmSystem.ChangeState(StateType.FSM_JUMP);
        }

        if (Mathf.Abs(player.h) == 0 && Mathf.Abs(player.v) == 0)
        {
            fsmSystem.IsCanChange = true;
            if (player.IsInBattle)
            {
                fsmSystem.ChangeState(StateType.FSM_ATTACKIDLE);
            }
            else
            {
                fsmSystem.ChangeState(StateType.FSM_IDLE);
            }
        }
        if (Input.GetMouseButton(0))
        {
            if (player.IsInBattle)
            {
                fsmSystem.IsCanChange = true;
                fsmSystem.ChangeState(StateType.FSM_ATTACK);
            }
        }
    }
示例#2
0
    public override void TriggerEvent(FsmSystem fsmSystem, GameObject gameObject)
    {
        Player player = gameObject.GetComponent <Player>();


        if (Mathf.Abs(player.h) < 0.1f && Mathf.Abs(player.v) < 0.1f)
        {
            fsmSystem.IsCanChange = true;
            if (player.IsInBattle)
            {
                fsmSystem.ChangeState(StateType.FSM_ATTACKIDLE);
            }
            else
            {
                fsmSystem.ChangeState(StateType.FSM_IDLE);
            }
        }
    }
示例#3
0
 public override void TriggerEvent(FsmSystem fsmSystem, GameObject gameObject)
 {
     //现在的动画状态
     AnimatorStateInfo currentBaseState = gameObject.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0);
     if (currentBaseState.normalizedTime > 1 && currentBaseState.IsName("Jump"))
     {
         fsmSystem.IsCanChange = true;
         fsmSystem.ChangeState(StateType.FSM_IDLE);
     }
 }
示例#4
0
    public override void TriggerEvent(FsmSystem fsmSystem, GameObject gameObject)
    {
        Player            player           = gameObject.GetComponent <Player>();
        AnimatorStateInfo currentBaseState = gameObject.GetComponent <Animator>().GetCurrentAnimatorStateInfo(1);

        if (player.IsInBattle && Mathf.Abs(player.h) > 0.1f || Mathf.Abs(player.v) > 0.1f)
        {
            fsmSystem.IsCanChange = true;
            fsmSystem.ChangeState(StateType.FSM_ATTACKWALK);
        }

        if (!player.IsInBattle && Mathf.Abs(player.h) > 0.1f || Mathf.Abs(player.v) > 0.1f)
        {
            fsmSystem.IsCanChange = true;
            fsmSystem.ChangeState(StateType.FSM_RUN);
        }

        if (Mathf.Abs(player.h) < 0.1f && Mathf.Abs(player.v) < 0.1f)
        {
            //如果离敌人距离过远
            if (true)
            {
                if (!stateChanging)
                {
                    player.StartCoroutine(DelayToInvokeDo(() => {
                        fsmSystem.IsCanChange = true;
                        player.IsInBattle     = false;
                        stateChanging         = false;
                        Debug.Log("进入攻击准备状态");
                        fsmSystem.ChangeState(StateType.FSM_IDLE);
                    }, 5.0f));
                    stateChanging = true;
                }
            }
        }

        if (Input.GetMouseButton(0))
        {
            fsmSystem.IsCanChange = true;
            fsmSystem.ChangeState(StateType.FSM_ATTACK);
        }
    }
示例#5
0
    public override void TriggerEvent(FsmSystem fsmSystem, GameObject gameObject)
    {
        Player player = gameObject.GetComponent <Player>();
        //
        AnimatorStateInfo currentBaseState = gameObject.GetComponent <Animator>().GetCurrentAnimatorStateInfo(1);

        if (currentBaseState.normalizedTime > 1 && (currentBaseState.IsName("Jab") || currentBaseState.IsName("Jab 0")))
        {
            fsmSystem.IsCanChange = true;
            fsmSystem.ChangeState(StateType.FSM_ATTACKIDLE);
        }
    }
示例#6
0
    public override void TriggerEvent(FsmSystem fsmSystem, GameObject gameObject)
    {
        GameObject player = GameObject.FindGameObjectWithTag("Player");

        float distance = (player.transform.position - gameObject.transform.position).magnitude;

        if (distance > 5)
        {
            fsmSystem.IsCanChange = true;
            fsmSystem.ChangeState(StateType.EnemyPatrol);
        }
    }
示例#7
0
    public override void TriggerEvent(FsmSystem fsmSystem, GameObject gameObject)
    {
        Player player = gameObject.GetComponent <Player>();

        if (Mathf.Abs(player.h) > 0.1f || Mathf.Abs(player.v) > 0.1f)
        {
            fsmSystem.IsCanChange = true;
            fsmSystem.ChangeState(StateType.FSM_RUN);
        }


        if (Input.GetKeyDown(KeyCode.Space))
        {
            fsmSystem.IsCanChange = true;
            fsmSystem.ChangeState(StateType.FSM_JUMP);
        }

        if (Input.GetKeyDown(KeyCode.Z))
        {
            fsmSystem.IsCanChange = true;
            fsmSystem.ChangeState(StateType.FSM_ATTACKIDLE);
        }
    }
示例#8
0
    private void Start()
    {
        EnemyFollowState followState = new EnemyFollowState();

        followState.onFixedUpdateMethod += onUpdateFollowState;
        EnemyPatrolState patrolState = new EnemyPatrolState();

        patrolState.onFixedUpdateMethod += onUpdatePatrolState;

        fsmSystem = new FsmSystem();
        fsmSystem.AddState(followState);
        fsmSystem.AddState(patrolState);
        fsmSystem.ChangeState(StateType.EnemyPatrol);

        enemy  = this.gameObject.GetComponent <EnemyCharacter>();
        player = GameObject.FindGameObjectWithTag("Player");
    }
示例#9
0
    // Use this for initialization
    void Start()
    {
        player = FindObjectOfType <Player>();

        IdleState idleState = new IdleState();

        idleState.onEnterMethod       += OnEnterIdleState;
        idleState.onUpdateMethod      += OnUpDateIdleState;
        idleState.onFixedUpdateMethod += OnFixedUpDateIdleState;
        RunState runState = new RunState();

        runState.onFixedUpdateMethod += OnFixedUpDateRunState;
        runState.onUpdateMethod      += OnUpDateRunState;
        runState.onEnterMethod       += OnEnterRunState;
        JumpState jumpState = new JumpState();

        jumpState.onEnterMethod += OnEnterJumpState;
        AttackIdleState AttackIdleState = new AttackIdleState();

        AttackIdleState.onEnterMethod  += OnEnterAttackIdleState;
        AttackIdleState.onUpdateMethod += OnUpdateAttackIdleState;

        AttackWalkState attackWalkState = new AttackWalkState();

        attackWalkState.onFixedUpdateMethod += OnFixedUpDateAttackWalkState;
        attackWalkState.onUpdateMethod      += OnUpDateAttackWalkState;
        attackWalkState.onEnterMethod       += OnEnterAttackWalkState;

        AttackDoState attackDoState = new AttackDoState();

        //attackDoState.onFixedUpdateMethod += OnFixedUpDateAttackWalkState;
        attackDoState.onUpdateMethod += OnUpDateAttackDoState;
        attackDoState.onEnterMethod  += OnEnterAttackDoState;

        fsmSystem = new FsmSystem();
        fsmSystem.AddState(idleState);
        fsmSystem.AddState(runState);
        fsmSystem.AddState(jumpState);
        fsmSystem.AddState(AttackIdleState);
        fsmSystem.AddState(attackWalkState);
        fsmSystem.AddState(attackDoState);
        fsmSystem.ChangeState(StateType.FSM_IDLE);
    }
 /*
  * private void OnAddLabelToAutoLocaList(UILabel label, string locaCode)
  * {
  *
  *  log.DebugMS("OnAddLabelToAutoLocaList - locaCode: " + locaCode);
  *  // translate directly, no language switching supported anyway
  *  label.text = Loca.Get(locaCode);
  * }
  */
 public void ChangeState(string stateName, object onEnterParams = null)
 {
     FsmSystem.ChangeState(stateName, onEnterParams);
 }
 protected void ChangeStateToPrevious(object onEnterParam = null)
 {
     FsmSystem.ChangeState(FsmSystem.PreviousStateName);
 }
 //Helper methods.
 protected void ChangeState(string newStateName, object onEnterParam = null)
 {
     FsmSystem.ChangeState(newStateName, onEnterParam);
 }
示例#13
0
 /// <summary>
 /// 改变状态机状态
 /// </summary>
 public void ChangeState(int stateType)
 {
     InternalSystem.ChangeState(stateType);
 }
示例#14
0
 public void OnButtonSkip()
 {
     FsmSystem.ChangeState("GameStateReadyForLogin");
 }