以下代码无法正确保存生成的IdleState
private void CreateLayerStates(AnimatorStateMachine sm,AnimationClip idleAnim)
{
List
ChildAnimatorState idleState = new ChildAnimatorState();
idleState.state.motion = idleAnim;
states.Add(idleState);
sm.states = states.ToArray();
}
需要使用AddState方法
private void CreateLayerStates(AnimatorStateMachine sm,AnimationClip idleAnim)
{
AnimatorState idleState = sm.AddState(idleStateName);
idleState.motion = idleAnim;
}
可能的原因
使用new生成的实例没有被unity正确的序列化到磁盘上,而AddState内部实现了序列化功能
使用AddTransition
同样的,以下代码也不会被正确保存
AnimatorStateTransition talkToIdle = new AnimatorStateTransition()
{
destinationState = idleState,
hasExitTime = true
};
talkState.AddTransition(talkToIdle);
需要改成
AnimatorStateTransition talkToIdle = talkState.AddTransition(idleState);
talkToIdle.hasExitTime = true;