animator下怎么控制指定动画的播放速度

 我来答
miniappYoh44tFFDbwZi
2016-02-01 · 请开发者输入账号签名
miniappYoh44tFFDbwZi
采纳数:14074 获赞数:18289

向TA提问 私信TA
展开全部
1,如果要改变速度的动画不多,比如就要停止和正常播放两种状态,可以使用blend tree 进行分支处理,一个是速度为0,一个为1的。
2,使用Time.timeScale.这没有深入研究,发现很多网站都有提及到。
3,使用UnityEditorInternal

UnityEditorInternal.AnimatorController ac = animator.runtimeAnimatorController as UnityEditorInternal.AnimatorController;

UnityEditorInternal.StateMachine sm = ac.GetLayer(1).stateMachine;
for (int i = 0; i < sm.stateCount; i++)
{
UnityEditorInternal.State state = sm.GetState(i);
state.speed = 2;
Debug.Log(state.uniqueName + " " + state.speed);
}

void SetAnimSpeedWithClipTag(int layer, string tag, float speed)
{
UnityEditorInternal.AnimatorController ac = animator.runtimeAnimatorController as UnityEditorInternal.AnimatorController;
UnityEditorInternal.StateMachine sm = ac.GetLayer(layer).stateMachine;
for (int i = 0; i < sm.stateCount; i++)
{
UnityEditorInternal.State state = sm.GetState(i);
if (state.tag == tag) //Change speed for all clip with the tag specified
state.speed = speed;
}
}

void SetAnimSpeedWithClipName(int layer, string name, float speed)
{
UnityEditorInternal.AnimatorController ac = animator.runtimeAnimatorController as UnityEditorInternal.AnimatorController;
UnityEditorInternal.StateMachine sm = ac.GetLayer(layer).stateMachine;
for (int i = 0; i < sm.stateCount; i++)
{
UnityEditorInternal.State state = sm.GetState(i);
if (state.uniqueName == name) //Change speed for only the clip name specified
state.speed = speed;
}
}

void SetAnimSpeedOfLayer(int layer, float speed)
{
UnityEditorInternal.AnimatorController ac = animator.runtimeAnimatorController as UnityEditorInternal.AnimatorController;
UnityEditorInternal.StateMachine sm = ac.GetLayer(layer).stateMachine;
for (int i = 0; i < sm.stateCount; i++)
{
//Change speed for all animation state in the layer
UnityEditorInternal.State state = sm.GetState(i);
state.speed = speed;
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式