//OnStateExit is called before OnStateExit is called on any state inside this state machine public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { AnimatorClipInfo aci = animator.GetCurrentAnimatorClipInfo(layerIndex)[0]; Debug.Log("离开:" + aci.clip.name + "-" + stateInfo.fullPathHash + "-" + stateInfo.length + "-" + stateInfo.normalizedTime + "-" + (stateInfo.normalizedTime - prev)); //Debug.Log(3 + "-" + stateInfo.fullPathHash + "-" + stateInfo.length + "-" + stateInfo.normalizedTime + "-" + (stateInfo.normalizedTime - prev)); prev = stateInfo.normalizedTime; }
/// <summary> /// Returns true when the current current animation is playing. /// </summary> /// <param name="name">name of animation</param> /// <param name="animator">animator object</param> /// <returns></returns> public static bool IsAnimationPlaying(string name, Animator animator) { for (int i = 0; i < animator.layerCount; i++) { AnimatorClipInfo[] clipInfoArray = animator.GetCurrentAnimatorClipInfo(i); foreach (AnimatorClipInfo info in clipInfoArray) if (info.clip.name.Equals(name)) return true; } return false; }
// Use this for initialization void Start() { sktAnimator = GetComponent<SkeletonAnimator>(); if (sktAnimator == null) { Debug.LogError("sktAnimator == null"); } else { sktAnimator.GetSkeleton().flipX = true; sktAnimator.GetSkeleton().SetColor(new Color(1.0f, 0.0f, 0.0f)); } sktAnimation = GetComponent<SkeletonAnimation>(); if (sktAnimation == null) { Debug.LogError("sktAnimation == null"); } else { Debug.Log("animation : " + sktAnimation.state.GetCurrent(0)); } animator = GetComponent<Animator>(); if (animator == null) { Debug.LogError("animator == null"); } else { AnimatorClipInfo[] items = animator.GetCurrentAnimatorClipInfo(0); Debug.Log("items length : " + items.Length); foreach (AnimatorClipInfo item in items) { Debug.Log("" + item.clip.name); } Debug.Log("ok"); // Debug.Log ("animator : " + animator.GetComponent<UnityEngine.Animation>().name); } sktUtility = GetComponent<SkeletonUtility>(); if (sktUtility == null) { Debug.LogError ("sktUtility == null"); } else { Debug.Log ("123123" + sktUtility.skeletonAnimation.Skeleton.Slots); // foreach (Slot item in sktUtility.skeletonAnimation.Skeleton.Slots) // { // Debug.Log ("item : " + item.ToString()); // if (item.ToString().Equals("front_bracer")) // { // item.SetColor(new Color(0.0f, 1.0f, 0.0f)); // } // } } }
// OnStateEnter is called before OnStateEnter is called on any state inside this state machine public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { Debug.Log(1 + "-" + stateInfo.fullPathHash + "-" + Animator.StringToHash("Base.Idle.idle1")+"-"+ stateInfo.length + "-" + stateInfo.normalizedTime + "-" + (stateInfo.normalizedTime - prev)); prev = stateInfo.normalizedTime; // animationManager.initState(animator, stateInfo); AnimationEvent ae = new AnimationEvent(); ae.functionName = "animationEvent"; AnimatorTransitionInfo ati = animator.GetAnimatorTransitionInfo(layerIndex); AnimatorClipInfo aci = animator.GetCurrentAnimatorClipInfo(layerIndex)[0]; aci.clip.AddEvent(ae); Debug.Log( "进入:"+ aci.clip.name +"-"+ stateInfo.fullPathHash + "-" + stateInfo.length + "-" + stateInfo.normalizedTime + "-" + (stateInfo.normalizedTime - prev)); //animator.SetInteger("idle",Random.Range(1, 3)); //AnimationAction animationAction = AnimationManager.getAnimationAction(animator); }
// OnStateUpdate is called before OnStateUpdate is called on any state inside this state machine public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { Debug.Break(); AnimatorTransitionInfo ati = animator.GetAnimatorTransitionInfo(layerIndex); AnimatorClipInfo []acis = animator.GetCurrentAnimatorClipInfo(layerIndex); string acit = ""; foreach (AnimatorClipInfo aci in acis){ acit += "["+aci.weight + ":" + aci.clip.name+"],"; } //Debug.Log(2 + "-[" + ati.normalizedTime + "]-["+animator.GetCurrentAnimatorClipInfo(layerIndex)[0].clip.name+ "]-["+stateInfo.normalizedTime+"]-"+ (stateInfo.normalizedTime-prev)); prev = stateInfo.normalizedTime; Debug.Log("update:" + stateInfo.fullPathHash+"-"+acit+stateInfo.normalizedTime); if (stateInfo.normalizedTime>0.8f) { // Debug.Log(stateInfo.fullPathHash); //animator.SetInteger("Attack", 0); //Debug.Break(); } }
private IEnumerator _AnimateFantasy() { m_fantasyModel = GameObject.Find("FantasyCharacter").GetComponent<Animator>(); m_fantasyModel.SetBool("IdleToIdle", false); m_fantasyModel.SetBool("AttackToIdle", false); m_fantasyModel.SetBool("IdleToAttack", true); yield return new WaitForSeconds(0.3f); float animationLength = m_fantasyModel.GetCurrentAnimatorClipInfo(0)[0].clip.length; yield return new WaitForSeconds(animationLength - 0.2f); m_fantasyModel.SetBool("IdleToIdle", true); m_fantasyModel.SetBool("IdleToAttack", false); m_fantasyModel.SetBool("AttackToIdle", true); }
private IEnumerator _AnimateComicBook() { m_comicBookModel = GameObject.Find("ComicCharacter").GetComponent<Animator>(); m_comicBookModel.SetBool("IdleToIdle", false); m_comicBookModel.SetBool("AttackToIdle", false); m_comicBookModel.SetBool("IdleToAttack", true); yield return new WaitForSeconds(0.3f); Debug.Log("Animator clip info = " + m_comicBookModel.GetCurrentAnimatorClipInfo(0)); float animationLength = m_comicBookModel.GetCurrentAnimatorClipInfo(0)[0].clip.length; yield return new WaitForSeconds(animationLength); m_comicBookModel.SetBool("IdleToIdle", true); m_comicBookModel.SetBool("IdleToAttack", false); m_comicBookModel.SetBool("AttackToIdle", true); }
// Use this for initialization void Start () { animator = GetComponent<Animator>(); AnimatorClipInfo[] clipInfo = animator.GetCurrentAnimatorClipInfo(0); //Debug.Log(clipInfo[0].clip.length); Destroy(this.gameObject, clipInfo[0].clip.length); }
// Use this for initialization void Start() { anim = GetComponent<Animator>(); timer = Time.time + anim.GetCurrentAnimatorClipInfo(0).Length; }