Unity 获取Animation,Animator,SkeletonAnimation的状态

Animation

#region  //控制Animation的播放
    private void onAnimationGui()//(GameObject obj)
    {
        Animation animation = gameObject.transform.GetComponentInChildren();  
        // Animator animator = obj.transform.GetComponentInChildren(); 
        int count = 0;
        if(animation.gameObject.transform.parent.gameObject.activeSelf)
        {
            foreach(AnimationState _state in animation)
            {                
                if (GUI.Button(new Rect(Vector2.up * 60*(count+1), new Vector2(150, 50)), "Play  "+_state.name))
                {
                    if(null != _state)
                    {
                        animation.enabled = true;
                        animation.Play(_state.name);
                        Debug.Log("当前播放的是"+animation.name+"--------------"+_state.name+"----动画");                
                    }
                }                
                count += 1;
                Debug.Log("clips.lenght=======333333333333333333333333333333333333333333=====animation"+animation);
            }                 
            if (GUI.Button(new Rect(Vector2.up * 60*(count+1), new Vector2(150, 50)), "重置Reset"))                
            {
                gameObject.transform.localPosition = originPos;
                Debug.Log("重置回初始状态");
            }   
            Debug.Log("clips.lenght=======44444444444444444444444444444444444444444444444444=====");

            setScaleController(count +2,animation.gameObject);
            Debug.Log("clips.lenght=======44444444444444444444444444444444444444444444444444====="); 
        }                     
    }
    #endregion

Animator


#region  //控制Animator的播放
    private void onAnimatorGui()//(GameObject obj)
    {
        Animator animator = gameObject.transform.GetComponentInChildren();  
        // Animator animator = obj.transform.GetComponentInChildren(); 
        if(animator.gameObject.transform.parent.gameObject.activeSelf)
        {
            AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;                    
            for(int i = 0;i

SkeletonAnimation

#region 控制spine的播放
    private void onSpineGui()
    {
        SkeletonAnimation spineAni = gameObject.transform.GetComponentInChildren();          
        int count = 0;
        if(spineAni.gameObject.transform.parent.gameObject.activeSelf)
        {
            var aa = spineAni.skeleton.data.Animations.ToArray();
            for(int i = 0;i().enabled = true;
                        spineAni.state.SetAnimation(0, aa[i].name, true);
                        Debug.Log("当前播放的是"+spineAni.GetComponent().name+"--------------"+aa[i].name+"----动画");                
                    }
                }                
                count += 1;                
            }
                         
            if (GUI.Button(new Rect(Vector2.up * 60*(count+1), new Vector2(150, 50)), "重置Reset"))                
            {
                gameObject.transform.localPosition = originPos;
                Debug.Log("重置回初始状态");
            }               
            setScaleController(count +2,spineAni.gameObject);            
        }                     
    }
    #endregion

你可能感兴趣的:(Unity 获取Animation,Animator,SkeletonAnimation的状态)