The Animator Override Controller is a type of asset which allows you to extend an existing Animator Controller, replacing the specific animations used but otherwise retaining the original’s structure, parameters and logic.
动画覆盖器是一类asset,它允许你扩张已经存在的动画控制器,用特定的animations 但是需要保留原始的结构、参数和逻辑;
This allows you to create multiple variants of the same basic state machine, but with each using different sets of animations.
这就允许你创建同一个基础状态机的多个变种,这些变种使用不同的animations
For example, your game may have a variety of NPC types living in the world, but each type (goblin, ogre, elf, etc) has their own unique animations for walking, idling, sitting, etc.
例如:你有一系列的npc生活在游戏中,他们有自己的独特走、idle、坐等animations;
By creating one “base” Animator Controller containing the logic for all NPC types, you could then create an override for each type and drop in their respective animation files.
To demonstrate, here’s a typical Animator Controller asset:
创建一个基础动画控制器,包含所有种类npc的逻辑,你就可以创建一个override为每一种NPC,然后用他们各自的animation去填充;
using UnityEngine; using System.Collections; public class AnimatorOveridePerformance : MonoBehaviour { public bool m_test = true; Animator m_animator = null; AnimatorOverrideController m_Old = null; AnimatorOverrideController m_New = null; // Use this for initialization void Start () { m_animator = GetComponent<Animator>(); m_Old = new AnimatorOverrideController(); m_New = Resources.Load<AnimatorOverrideController>("Packages/ArtWorks/Player/M2/M2_P04/M2_P04"); Debug.LogError(m_New); m_Old = (AnimatorOverrideController)m_animator.runtimeAnimatorController; if (null != m_New) { Debug.LogError(m_Old["P01Attack01"]); Debug.LogError(m_Old["P01Attack02"]); m_Old["P01Attack01"] = m_New["P04Attack01"]; m_Old["P01Attack02"] = m_New["P04Attack02"]; Debug.LogError(m_Old["P01Attack01"]); Debug.LogError(m_Old["P01Attack02"]); } } void Update() { Profiler.BeginSample("Update"); if (m_test && m_New) { Profiler.BeginSample("this[]"); m_Old["P01Attack01"] = m_New["P04Attack01"]; m_Old["P01Attack02"] = m_New["P04Attack02"]; Profiler.EndSample(); } Profiler.EndSample(); } }
单次消耗大概在0.5到1ms