Unity AnimatorController注意事项

本文介绍了在Unity中如何为游戏对象的Animator组件正确赋值AnimatorController。对于通过AssetBundle加载的AnimatorController,可以直接赋值;而对于通过Resource.load加载的,需要使用Instantiate方法。这是因为Resource加载的资源没有引用计数,而AssetBundle加载的会自动处理引用计数。

通过assetbundle加载的单独打包AnimatorController使用下面方法赋值

Go.GetComponent<Animator>().runtimeAnimatorController = (RuntimeAnimatorController) obj;


通过Resouce.load 加载的AnimatorController使用

Go.GetComponent<Animator>().runtimeAnimatorController = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(obj);


原因是Resouce实际没真正加载资源,而bundle方式资源以及被加载进来了

猜测是Resouce导入的没有引用计数,不会自动clone,而bundle会自动clone,并使用引用计数


IEnumerator Download(string url)
{
        WWW www = new WWW(url);
        yield return www;
        if (www.isDone)
        {
                if (!string.IsNullOrEmpty(www.error))
                {
                        Debug.LogError(www.error);
                        yield return true;
                }
                Object obj = [url=http://www.assetBundle.mainAsset]www.assetBundle.mainAsset[/url];
                if (obj != null)
                {
                        m_npc.GetComponent<Animator>().runtimeAnimatorController = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(obj);
                }
        }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值