使用AnimatorOverrideController动态更换animationclip注意事项

http://www.ceeger.com/forum/read.php?tid=19138

public AnimationClip clip;
Animator anim;
void Awake()
{
    anim = GetComponent();
}
void Start () {
    AnimatorOverrideController overrideController = new AnimatorOverrideController();
    overrideController.runtimeAnimatorController = anim.runtimeAnimatorController;
    overrideController["testCip"] = clip;
    anim.runtimeAnimatorController = overrideController;
}

这里一定要注意, overrideController["testCip"] = clip;里面的testClip不是状态机里面的状态名,而是实际要替换的clip的名字.....  


也可以用AnimationClipPair得到clip的名字

RuntimeAnimatorController tempController = anim.runtimeAnimatorController;
AnimatorOverrideController overrideController = new AnimatorOverrideController();
overrideController.runtimeAnimatorController = tempController;
overrideController.PerformOverrideClipListCleanup();//这个函数在U5.3和5.0都不存在应该是去掉了吧
 
 
overrideController[overrideController.clips[0].originalClip.name] = clip;
overrideController[overrideController.clips[1].originalClip.name] = clip2;
 
foreach (AnimationClipPair pairs in overrideController.clips)
{
    Debug.Log(pairs.originalClip.name );
    if (pairs.overrideClip!=null)
    {
        Debug.Log(pairs.overrideClip.name );
    }
}
 
anim.runtimeAnimatorController = overrideController;


转载于:https://www.cnblogs.com/nafio/p/9137366.html

你可能感兴趣的:(使用AnimatorOverrideController动态更换animationclip注意事项)