查看: 457|回复: 0
打印 上一主题 下一主题

[其他] 获取正在播放动画的名称

[复制链接]

9903

主题

126

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
53456
精华
316

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2015-8-29 02:19:29 |只看该作者 |倒序浏览
获取动画时间的名称,在旧版动画(Animation)中使用如下代码:

using UnityEngine;
using System.Collections;
publicclass ScreenShake : MonoBehaviour
{
    privatefloat shakeTime = 0.0f;
    privatefloat fps= 20.0f;
    privatefloat frameTime =0.0f;
    privatefloat shakeDelta =0.005f;
    public  Camera cam ;
    publicstaticbool isshakeCamera =false;
    // Use this for initializationvoid Start ()
    {
        shakeTime = 2.0f;
        fps= 20.0f;
        frameTime =0.03f;
        shakeDelta =0.005f;
   //isshakeCamera=true;
    }
   
    // Update is called once per framevoid Update ()
    {
        if (isshakeCamera)
        {
            if(shakeTime > 0)
            {
                shakeTime -= Time.deltaTime;
                if(shakeTim
e <= 0)
                {
                    cam.rect = new Rect(0.0f,0.0f,1.0f,1.0f);
                    isshakeCamera =false;
                    shakeTime = 1.0f;
                    fps= 20.0f;
                    frameTime =0.03f;
                    shakeDelta =0.005f;
                }
                else
                {
                    frameTime += Time.deltaTime;
                    
                    if(frameTime > 1.0 / fps)
                    {
                        frameTime = 0;
                        cam.rect = new Rect(shakeDelta * ( -1.0f + 2.0f * Random.value),shakeDelta * ( -1.0f + 2.0f * Random.value), 1.0f, 1.0f);
                    }
                }
            }
        }
    }
}

新版动画(Animator)使用如下代码:
AnimatorClipInfo[] animInfo = anim.GetCurrentAnimatorClipInfo(0);


           foreach (var item in animInfo)
           {
               print(item.clip.name);
           }



分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-4-29 05:39 , Processed in 0.081218 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部