animator下怎么控制指定动画的播放速度
1个回答
展开全部
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;
}
}
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;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询