示例#1
0
    static void AddTransitionParam(AnimatorState from, AnimatorState to, AnimatorStateTransition transition)
    {
        Debug.LogError("from:" + from.name + " ->   to:" + to);
        AnimatState       f_state   = (AnimatState)System.Enum.Parse(typeof(AnimatState), from.name);
        AnimatState       t_state   = (AnimatState)System.Enum.Parse(typeof(AnimatState), to.name);
        AnimatorTransInfo transInfo = InfoMgr <AnimatorTransInfo> .Instance.GetInfo((int)f_state);

        switch (t_state)
        {
        case AnimatState.AnimaState_IDLE:
            ParseTransitionParam(transInfo.idle, transition);
            break;

        case AnimatState.AnimaState_FREE:
            ParseTransitionParam(transInfo.free, transition);
            break;

        case AnimatState.AnimaState_WALK:
            ParseTransitionParam(transInfo.walk, transition);
            break;

        case AnimatState.AnimaState_ATK1:
            ParseTransitionParam(transInfo.atk1, transition);
            break;

        case AnimatState.AnimaState_ATK2:
            ParseTransitionParam(transInfo.atk2, transition);
            break;

        case AnimatState.AnimaState_ATK3:
            ParseTransitionParam(transInfo.atk3, transition);
            break;

        case AnimatState.AnimaState_SKILL1:
            ParseTransitionParam(transInfo.skill1, transition);
            break;

        case AnimatState.AnimaState_SKILL2:
            ParseTransitionParam(transInfo.skill2, transition);
            break;

        case AnimatState.AnimaState_SKILL3:
            ParseTransitionParam(transInfo.skill3, transition);
            break;

        case AnimatState.AnimaState_DIE:
            ParseTransitionParam(transInfo.die, transition);
            break;

        case AnimatState.AnimaState_LIVE:
            ParseTransitionParam(transInfo.live, transition);
            break;
        }
    }
示例#2
0
    static void SetTransitionParam(AnimatorControllerLayer controllLayer)
    {
        ChildAnimatorState[] states = controllLayer.stateMachine.states;
        for (int i = 0; i < states.Length; i++)
        {
            AnimatState state = (AnimatState)System.Enum.Parse(typeof(AnimatState), states[i].state.name);
            switch (state)
            {
            case AnimatState.AnimaState_IDLE:

                break;

            case AnimatState.AnimaState_FREE:

                break;

            case AnimatState.AnimaState_WALK: break;

            case AnimatState.AnimaState_ATK1: break;

            case AnimatState.AnimaState_ATK2: break;

            case AnimatState.AnimaState_ATK3: break;

            case AnimatState.AnimaState_SKILL1: break;

            case AnimatState.AnimaState_SKILL2: break;

            case AnimatState.AnimaState_SKILL3: break;

            case AnimatState.AnimaState_DIE: break;

            case AnimatState.AnimaState_LIVE: break;
            }

            Debug.LogError(states[i].state.name);
            AnimatorStateTransition[] transtions = states[i].state.transitions;
            for (int j = 0; j < transtions.Length; j++)
            {
                //transtions[j].
            }
        }
    }
示例#3
0
    // Update is called once per frame
    void Update()
    {
        if (transform.position.x < 10.0f || transform.position.x > 140.0f || transform.position.z < 10.0f || transform.position.z > 10.0f)
                        nma.destination = new Vector3 (10, 10, 10);
                distance = Vector3.Distance (playerTransform.position, transform .position);
                if (distance < 5) {
                        //dot_01 = Vector3.Dot ((playerTransform.position - transform .position).normalized, transform.position.normalized);
                        if (backCannotFindPlayer) {
                                dotToPlayer = Vector3.Dot ((playerTransform.position - transform .position).normalized, transform.forward);

                        } else {
                                dotToPlayer = 1;
                        }

                }

                myTime2 += Time.deltaTime;
                myTime += Time .deltaTime;
                if (myTime > 30.0f)
                        myTime = 0;

                if (distance < 4.0f & dotToPlayer > 0)
                        runBool = true;
                if (distance > 10.0f) {
                        runBool = false;
                        keyBool = true;
                }

                if (runBool)
                        myState = AnimatState.Run;
                else if (myTime < 10.0f)
                        myState = AnimatState.Idle;
                else if (myTime < 30.0f)
                        myState = AnimatState.Walk;
                switch (myState) {
                case AnimatState.Idle:
                        nma.destination = transform .position;
                        myAnimation.Play ("idle");
                        break;
                case AnimatState.Walk:
                        if (myTime2 > 10.0f) {
                                nma.destination = RayHitPoint ();
                                myTime2 = 0;
                        }
                        myAnimation.Play ("walk");
                        nma.speed = 1.0f;
                        break;
                case AnimatState.Run:
                        if (keyBool) {
                                hitPoint = RayHitPoint ();
                                if (Vector3.Distance (hitPoint, playerTransform .position) > 20.0f) {

                                        float dotKey = Vector3.Dot (playerTransform .position - hitPoint, playerTransform.forward);
                                        if (dotKey < 0) {
                                                nma.destination = hitPoint;

                                                keyBool = false;
                                        }
                                }
                        }
                        myAnimation.Play ("run");
                        nma.speed = 2.0f;
                        break;
                }
    }
示例#4
0
		// Update is called once per frame
		void  Update ()
		{
				distance = Vector3.Distance (playerTransform.position, transform .position);
				if (distance < 5) {
						dotToEnemy = Vector3.Dot ((transform.position - playerTransform.position).normalized, playerTransform.forward);
				}
				if (backCannotFindPlayer) {
						dotToPlayer = Vector3.Dot ((playerTransform.position - transform .position).normalized, transform.forward);
			
				} else {
						dotToPlayer = 1;
			
				}
				
				myTime += Time.deltaTime;
				
				
				

				if (distance < hitMinDistance) {
						//if (dotToPlayer > 0)
						hitBool = true;
						if (dotToEnemy > 0.5f)
								inGetHitBool = true;
						else {
								inGetHitBool = false;
						}
				}
				if (distance > hitMaxDistance) {
						hitBool = false;
						inGetHitBool = false;
				}
				if (distance < 5) {
						if (dotToPlayer > 0)//是否在前方
								moveFreeBool = false;
				}
				if (distance > 8)
						moveFreeBool = true;
				
				//if (!solider_animation.hitEnemy) {
				//keyBool = true;
				//}

				if (myLife < 0 || deathBool) {
						myState = AnimatState.Death;
				} else if (getHitBool) {
						myState = AnimatState.GetHit;
				} else if (hitBool) {
						myState = AnimatState.Hit;
				} else if (moveFreeBool) {
						myState = AnimatState.Movefree;
				} else {
						myState = AnimatState.MoveToplayer;
				}

				

				switch (myState) {
				case AnimatState.Idle:
						nma.destination = transform.position;
						myAnimation.Play ("idle");
						break;
				case AnimatState.Movefree:
						if (myTime > 10) {
								nma.destination = RayHitPoint ();
								myTime = 0;

						}
						myAnimation.Play ("walk");
						break;
				case AnimatState.MoveToplayer:
						
						myAnimation.PlayQueued ("walk", QueueMode.CompleteOthers);
						if (myAnimation.IsPlaying ("hit") || myAnimation.IsPlaying ("death")) {
								nma.destination = transform.position;
								
						} else {
								nma.destination = playerTransform.position;
						}
					
						
						
						break;
				case AnimatState.Hit:
						
						transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (new Vector3 (playerTransform.position.x, transform.position.y, playerTransform.position .z) - transform .position), 1.0f);
						nma.destination = transform.position;
						myAnimation.Play ("hit");
						myAnimation ["hit"].speed = hitSpeed;
						hitPlayer ();
						break;
				case AnimatState.GetHit:
					

						//transform.Translate (0.05f * transform.forward .x, 0.05f * transform.forward .y, -transform.forward .z * 0.05f);
						myTimeGetHitStart += Time .deltaTime;
						myTimeGetHitEnd -= Time .deltaTime;
						nma.destination = transform.position;
						myAnimation.Play ("getHit");
						if (myTimeGetHitStart > animation ["getHit"].clip.length / 2) {
								myAnimation ["getHit"].speed = 0;
						}
						if (myTimeGetHitEnd < 0) {
								getHitBool = false;
								myAnimation ["getHit"].speed = 0.5f;
						}
						//StartCoroutine (Wait ()); 
						break;
				case AnimatState.Death:
						nma.destination = transform.position;
						myAnimation.Play ("death");
						deathMoveTime += Time.deltaTime;
						if (deathMoveTime < 0.4f) {
								transform.Translate (0, 0.8f, -0.05f);
						} else if (deathMoveTime < 0.8f) {
								transform.Translate (0, -0.01f, 0);
						} else if (deathMoveTime > 1.0f) {
								deathBool = false;
								deathMoveTime = 0;
								getHitBool = false;
						}
						break;
		
				}
				
					
							
						
				
		}
示例#5
0
		// Update is called once per frame
		void  Update ()
		{
				distance = Vector3.Distance (playerTransform.position, transform .position);
				if (distance < 5) {
						dotToEnemy = Vector3.Dot ((transform.position - playerTransform.position).normalized, playerTransform.forward);
				}
				if (backCannotFindPlayer) {
						dotToPlayer = Vector3.Dot ((playerTransform.position - transform .position).normalized, transform.forward);
			
				} else {
						dotToPlayer = 1;
			
				}
		
				myTime += Time.deltaTime;
		
		
		
		
				if (distance < hitMinDistance) {
						//if (dotToPlayer > 0)
						hitBool = true;
						if (dotToEnemy > 0.5f)
								inGetHitBool = true;
						
				}
				if (distance > hitMaxDistance) {
						hitBool = false;
						inGetHitBool = false;
				}
				if (distance < 5) {
						if (dotToPlayer > 0)//是否在前方
								moveFreeBool = false;
				}
				if (distance > 8)
						moveFreeBool = true;
		
				//if (!solider_animation.hitEnemy) {
				//keyBool = true;
				//}
		
				if (myLife < 0) {
						myState = AnimatState.Death;
				} else if (hitBool) {
						myTime1 += Time .deltaTime;
						if (myTime1 < myAnimation ["hit"].clip.length) {
								myState = AnimatState.Hit;
						} else {
								myState = AnimatState.Idle;
								
						}
				} else if (moveFreeBool) {
						myState = AnimatState.Movefree;
				} else {
						myState = AnimatState.MoveToplayer;
						
				}
		
		
		
				switch (myState) {
				case AnimatState.Idle:
						
						transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (new Vector3 (playerTransform.position.x, transform.position.y, playerTransform.position .z) - transform .position), 1.0f);
						nma.destination = transform.position;
						myAnimation.Play ("idle");
						if (myTime1 > 3.0f)
								myTime1 = 0;
						break;
				case AnimatState.Movefree:
						if (myTime > 10) {
								nma.destination = RayHitPoint ();
								myTime = 0;
				
						}
						myAnimation.Play ("walk");
						break;
				case AnimatState.MoveToplayer:
			
						myAnimation.PlayQueued ("walk", QueueMode.CompleteOthers);
						if (myAnimation.IsPlaying ("hit") || myAnimation.IsPlaying ("death") || myAnimation.IsPlaying ("idle")) {
								nma.destination = transform.position;
								
						} else {
								nma.destination = playerTransform.position;
						}
						
			
						break;
				case AnimatState.Hit:
			
						transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (new Vector3 (playerTransform.position.x, transform.position.y, playerTransform.position .z) - transform .position), 1.0f);
						nma.destination = transform.position;
						myAnimation.Play ("hit");
						myAnimation ["hit"].speed = hitSpeed;
						hitPlayer ();
						
						break;
		
				case AnimatState.Death:
						nma.destination = transform.position;
						myAnimation.Play ("death");
						animator.speed = 1.0f;
						if (StartCoroutineBool) {
								StartCoroutine (deathWait ());
								StartCoroutineBool = false;
						}
						
						break;
			
				}
		
		
		
		
		
		}