找回密码
 立即注册
查看: 424|回复: 0

Unity 获取Animation,Animator,SkeletonAnimation的状态

[复制链接]
发表于 2022-2-16 16:33 | 显示全部楼层 |阅读模式
Animation

#region  //控制Animation的播放    private void onAnimationGui()//(GameObject obj)    {        Animation animation = gameObject.transform.GetComponentInChildren<Animation>();          // Animator animator = obj.transform.GetComponentInChildren<Animator>();         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=====");         }                         }    #endregionAnimator

#region  //控制Animator的播放    private void onAnimatorGui()//(GameObject obj)    {        Animator animator = gameObject.transform.GetComponentInChildren<Animator>();          // Animator animator = obj.transform.GetComponentInChildren<Animator>();         if(animator.gameObject.transform.parent.gameObject.activeSelf)        {            AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;                                for(int i = 0;i<clips.Length;i++)            {                                //根据动画名字 添加对应的动画按钮                if (GUI.Button(new Rect(Vector2.up * 60*(i+1), new Vector2(150, 50)), "Play  "+clips.name))                {                    // GUI.GUIStyle.fontSize = 60;                    if(null != animator)                    {                        animator.enabled = true;                        animator.Play(clips.name);                                            }                }                                            }                    if (GUI.Button(new Rect(Vector2.up * 60*(clips.Length+1), new Vector2(150, 50)), "重置Reset"))                            {                gameObject.transform.localPosition = originPos;                Debug.Log("重置回初始状态");            }               setScaleController(clips.Length,animator.gameObject);            Debug.Log("clips.lenght=======44444444444444444444444444444444444444444444444444=====");         }                         }    #endregionSkeletonAnimation

#region 控制spine的播放    private void onSpineGui()    {        SkeletonAnimation spineAni = gameObject.transform.GetComponentInChildren<SkeletonAnimation>();                  int count = 0;        if(spineAni.gameObject.transform.parent.gameObject.activeSelf)        {            var aa = spineAni.skeleton.data.Animations.ToArray();            for(int i = 0;i<aa.Length;i++)            {                if (GUI.Button(new Rect(Vector2.up * 60*(count+1), new Vector2(150, 50)), "Play  "+aa.name))                {                    if(null != spineAni)                    {                        spineAni.GetComponent<SkeletonAnimation>().enabled = true;                        spineAni.state.SetAnimation(0, aa.name, true);                        Debug.Log("当前播放的是"+spineAni.GetComponent<SkeletonAnimation>().name+"--------------"+aa.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开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-9-22 19:31 , Processed in 0.090008 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表