纳金网
标题:
animator动画从指定帧开始播放
[打印本页]
作者:
烟雨
时间:
2019-11-28 15:32
标题:
animator动画从指定帧开始播放
来自: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);
}
}
}
复制代码
欢迎光临 纳金网 (http://rs.narkii.com/club/)
Powered by Discuz! X2.5