栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > 其他

Unity——Animator如何获取所有动画以及如何动态分帧播放

其他 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Unity——Animator如何获取所有动画以及如何动态分帧播放

 

静态Editor方法,可参考

真Unity3d_分享一个Animator帮助类_大话程序员-CSDN博客

今天分享一个动态(Runtime)获取Animator所有动画代码:
public Animator _animator;
    AnimationClip nowPlay;
    public Dictionary animationClips;
    void Awake()
    {
        //animator.get
        animationClips = new Dictionary();
        _animator = GetComponent();
        if (_animator != null)
        {
            var animations = _animator.runtimeAnimatorController.animationClips;
            for(int i = 0; i < animations.Length; ++i)
            {
                var anim = animations[i];
                animationClips[anim.name] = anim;
            }

            if (nowPlay == null && animationClips.Count > 0)
            {
                nowPlay = animationClips.ElementAt(0).Value;
                _animator.Play(nowPlay.name, 0, 0.001f);//相当于一开始,即暂停
            }
        }
    }

只要用上Linq,就能用上面的代码

using System.Linq;
另外,定格播放的。。。代码
    private void Update()
    {
        if (nowPlay)
        {
            _animator.Play(nowPlay.name, 0, timeSlider);
        }        
    }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/905676.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号