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

[其他] animator动画从指定帧开始播放

[复制链接]

9903

主题

126

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
53456
精华
316

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

跳转到指定楼层
楼主
发表于 2019-11-28 15:32:34 |只看该作者 |倒序浏览

来自:18803836360
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;

  4. public class playIndexFrame : MonoBehaviour {

  5.     public Animator _currentAnimator;
  6.     Clip[] _acInfo;
  7.     /// <summary>
  8.     /// 假设的已经播放的动画帧数
  9.     /// </summary>
  10.     public float _hadPlay;
  11.     void Awake()
  12.     {
  13.         _acInfo = _currentAnimator.runtimeAnimatorController.animationClips;
  14.         Debug.Log(_acInfo[0].length * _acInfo[0].frameRate);
  15.     }

  16.     public void setSolidFrame(int _index)
  17.     {
  18.         //瞬间的隐藏于显示可以重置animator的动画
  19.         _currentAnimator.gameObject.SetActive(false);
  20.         _currentAnimator.gameObject.SetActive(true);
  21.         //确认动画速度正常
  22.         _currentAnimator.speed = 1;
  23.         _hadPlay = _index;
  24.         Debug.Log("动画的总的时间:"+_acInfo[0].length);
  25.         //已播放的帧数占据总帧数的比例
  26.         float _temp = _hadPlay / (_acInfo[0].length * _acInfo[0].frameRate);
  27.         Debug.Log(_temp);
  28.         //动画已经播放过的时长
  29.         Debug.Log(_temp * _acInfo[0].length);
  30.         //更新动画到指定帧
  31.         _currentAnimator.Update(_temp * _acInfo[0].length);
  32.     }


  33.     void Update()
  34.     {
  35.         if (Input.GetKeyDown(KeyCode.A))
  36.         {
  37.             setSolidFrame(10);
  38.         }
  39.         if (Input.GetKeyDown(KeyCode.S))
  40.         {
  41.             setSolidFrame(40);
  42.         }
  43.         if (Input.GetKeyDown(KeyCode.D))
  44.         {
  45.             setSolidFrame(80);
  46.         }
  47.         if (Input.GetKeyDown(KeyCode.F))
  48.         {
  49.             setSolidFrame(120);
  50.         }
  51.     }
  52. }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

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

关闭

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

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

GMT+8, 2024-4-29 04:31 , Processed in 0.079164 second(s), 29 queries .

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

© 2008-2019 Narkii Inc.

回顶部