码迷,mamicode.com
首页 > 其他好文 > 详细

Animator Override Controllers 学习及性能测试

时间:2016-01-16 16:52:03      阅读:424      评论:0      收藏:0      [点我收藏+]

标签:

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

Animator Override Controllers 学习及性能测试

标签:

原文地址:http://www.cnblogs.com/panyingying/p/5135647.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!