Exemplo n.º 1
0
        public override void Enter(StateMachine obj)
        {
            AgentState s = obj.controller.GetState();
            GameObject t = obj.FindClosestEnemy();

            obj.controller.SetMovementTarget(t.transform);

            Debug.Log("Enter " + this.GetType().Name + " : " + obj.agent.name + " --> " + obj.controller.GetState().Moving);
            //obj.agent.animation.CrossFade("walk");
        }
Exemplo n.º 2
0
 void StateMachineInit()
 {
     this.sm = new FSM.StateMachine();
     this.sm.addState(new PlayerIdle(this));
     this.sm.addState(new PlayerRun(this));
     this.sm.addState(new PlayerWalk(this));
     this.sm.addState(new PlayerRecycle(this));
     this.sm.addState(new PlayerShock(this));
     this.sm.addState(new PlayerDie(this));
     this.sm.SwitchState("idle");
 }
Exemplo n.º 3
0
 public override void Execute(StateMachine obj)
 {
     Debug.Log("Execute: " + this.GetType().Name + "  Time: " + Time.time);
     obj.controller.HealNow();
     if (obj.environment.enabled)
     {
         obj.ChangeState(obj.previousState);
     }
     else
     {
         obj.ChangeState(DeadState.GetInstance());
     }
 }
Exemplo n.º 4
0
        public override void Execute(StateMachine obj)
        {
            AgentState s = obj.controller.GetState();

               // s.AttackTarget = GameObject.Find("AttTarget");

            GameObject t = obj.FindClosestEnemy();
            float d = Vector3.Distance(obj.agent.transform.position, t.transform.position);

            Debug.Log(obj.agent.name + ":: " + d+" to "+t.transform.position);
            if (d > 20)
            {

                obj.ChangeState(RoamState.GetInstance());
            }
        }
Exemplo n.º 5
0
        public override void OnExecute(FSM.StateMachine stateMachine)
        {
            float       x           = Input.GetAxis("Horizontal");
            Rigidbody2D rigidbody2D = stateMachine.GetComponent <Rigidbody2D>();

            if (x > 0)
            {
                // 方向不变
                rigidbody2D.transform.eulerAngles = new Vector3(0, 0, 0);
            }
            else if (x < 0)
            {
                rigidbody2D.transform.eulerAngles = new Vector3(0, 180, 0);
            }

            // 移动的基本向量
            Vector3 runVector = new Vector3(x, 0, 0);

            rigidbody2D.transform.position += PlayerVariable.RunVelocity * Time.deltaTime * runVector;
        }
Exemplo n.º 6
0
 public override void Execute(StateMachine obj)
 {
     GameObject t = obj.FindClosestEnemy();
     float d = Vector3.Distance(obj.agent.transform.position, t.transform.position);
     if (obj.controller.GetState().AttackTarget == null || obj.controller.GetState().CurrentAttackType == -1)
     {
         obj.controller.SetAttack(AgentAttack.MEDIUM_RANGE);
         obj.controller.SetAttackTarget(t);
     }
     if (d < obj.controller.GetState().attackTypes[obj.controller.GetState().CurrentAttackType].range/2.0f)
     {
         obj.controller.GetState().Moving = false;
     }
     else if (d>30)
     {
         obj.controller.SetAttackTarget(null);
         obj.controller.SetAttack(-1);
         obj.ChangeState(InitialState.GetInstance());
     }
 }
Exemplo n.º 7
0
        public override void Execute(StateMachine obj)
        {
            AgentState s = obj.controller.GetState();

            if (s.CurrentPath != null && s.CurrentPath.IsDone())
            {
                obj.controller.GetState().Moving = true;
            }

               // s.AttackTarget = GameObject.Find("AttTarget");

            GameObject t = obj.FindClosestEnemy();
            obj.controller.SetMovementTarget(t.transform);

            float d = Vector3.Distance(obj.agent.transform.position, t.transform.position);

            Debug.Log(obj.agent.name + ":: " + d+" to "+t.transform.position);
            if (d <= 20 )
            {
                int layer = 1 << 9;
                if (!Physics.Raycast(obj.agent.transform.position, (t.transform.position-obj.agent.transform.position)/d,d,layer))
                    obj.ChangeState(ChaseState.GetInstance());
            }
        }
Exemplo n.º 8
0
 public override void OnEnter(FSM.StateMachine stateMachine)
 {
     stateMachine.Animator.SetBool(PlayerVariable.IsRun, true);
 }
Exemplo n.º 9
0
 public abstract void Exit(StateMachine obj);
Exemplo n.º 10
0
 public abstract void Execute(StateMachine obj);
Exemplo n.º 11
0
        public override void Enter(StateMachine obj)
        {
            Debug.Log("Enter " + this.GetType().Name);

            GameObject.Destroy(obj.agent);
        }
Exemplo n.º 12
0
        public override void Enter(StateMachine obj)
        {
            Debug.Log("Enter " + this.GetType().Name);

            obj.agent.animation.Play("jump_pose");
        }
Exemplo n.º 13
0
 public override void OnEnter(FSM.StateMachine stateMachine)
 {
     // 死亡则禁用状态机
     stateMachine.enabled = false;
 }
Exemplo n.º 14
0
 public override void Execute(StateMachine obj)
 {
     Debug.Log("Execute: " + this.GetType().Name + "  Time: " + Time.time);
 }
Exemplo n.º 15
0
 public override bool Predicate(FSM.StateMachine stateMachine)
 {
     return(Mathf.Abs(Input.GetAxis("Horizontal")) < 0.01f);
 }
Exemplo n.º 16
0
 public override void Exit(StateMachine obj)
 {
     obj.agent.GetComponent<AgentAI>()._state.Moving = false;
 }
Exemplo n.º 17
0
 public override void Enter(StateMachine obj)
 {
     Debug.Log("Enter " + this.GetType().Name);
     obj.agent.animation.CrossFade("run");
 }
Exemplo n.º 18
0
 public abstract void Enter(StateMachine obj);
Exemplo n.º 19
0
 public override void Exit(StateMachine obj)
 {
     Debug.Log("Exit " + this.GetType().Name);
 }
Exemplo n.º 20
0
 public override void OnEnter(FSM.StateMachine stateMachine)
 {
     // 触发 Idle 动画
     stateMachine.Animator.SetBool(PlayerVariable.IsRun, false);
 }