- 最后登录
- 2021-7-6
- 注册时间
- 2012-12-27
- 阅读权限
- 90
- 积分
- 76145
- 纳金币
- 53488
- 精华
- 316
|
来自:18803836360- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class playIndexFrame : MonoBehaviour {
- public Animator _currentAnimator;
- Clip[] _acInfo;
- /// <summary>
- /// 假设的已经播放的动画帧数
- /// </summary>
- public float _hadPlay;
- void Awake()
- {
- _acInfo = _currentAnimator.runtimeAnimatorController.animationClips;
- Debug.Log(_acInfo[0].length * _acInfo[0].frameRate);
- }
- public void setSolidFrame(int _index)
- {
- //瞬间的隐藏于显示可以重置animator的动画
- _currentAnimator.gameObject.SetActive(false);
- _currentAnimator.gameObject.SetActive(true);
- //确认动画速度正常
- _currentAnimator.speed = 1;
- _hadPlay = _index;
- Debug.Log("动画的总的时间:"+_acInfo[0].length);
- //已播放的帧数占据总帧数的比例
- float _temp = _hadPlay / (_acInfo[0].length * _acInfo[0].frameRate);
- Debug.Log(_temp);
- //动画已经播放过的时长
- Debug.Log(_temp * _acInfo[0].length);
- //更新动画到指定帧
- _currentAnimator.Update(_temp * _acInfo[0].length);
- }
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.A))
- {
- setSolidFrame(10);
- }
- if (Input.GetKeyDown(KeyCode.S))
- {
- setSolidFrame(40);
- }
- if (Input.GetKeyDown(KeyCode.D))
- {
- setSolidFrame(80);
- }
- if (Input.GetKeyDown(KeyCode.F))
- {
- setSolidFrame(120);
- }
- }
- }
复制代码 |
|