您的位置:首页 > 移动开发 > Unity3D

小解Unity如何抽换AC?

2018-10-14 11:41 15 查看

为什么要抽换AC?

对于超细的动画,做动画状态机有什么比较好的做法?现在我遇到这样一份动画素材:一个角色有单独带弓动画(边跑边射击,换武器、用于2D混合树的左右前后行走的:正常速度行走、快速行走,潜行)、单独带刀动画(和上面括号一样,武器变成了刀)、既带刀又带弓动画(和上面一样),此外还有些捡装备、吃药动画。总之动画很细很多,就像一个不断分叉的二叉树。我刚开始不知道这份素材那么细,所以我做到后面:用了很多父子关系的sub-state-machine和 2D blend tree。这样是否合理?不,肯定后面动画的Parameters会很多,代码也会很复杂。但是做到最后我发现这份动画是很规范的,每个大类包每个小类,所以我打算抽换Animation controller。有没有更好的方法?问了群里的老师,老师说可以用Timeline。不过这个只是针对于互动性较低的动画而已。

现在直接上代码吧。只介绍我的方法,非注释的部分。

  1. using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

public class Test1 : MonoBehaviour {

public Animator animator;
public RuntimeAnimatorController animNow;
string strPath;

//public AnimatorOverrideController[] Tankatate;

void Start () {

animator = GetComponent<Animator>();
//strPath = "Assets/Resources/ac1";//路径
//RuntimeAnimatorController anim = (RuntimeAnimatorController)Resources.Load("Assets/Resources/ac1");//加载资源
//Debug.Log("anim:" + anim);
//gameObject.GetComponent<Animator>().runtimeAnimatorController = anim;//赋值
//animNow = gameObject.GetComponent<Animator>().runtimeAnimatorController;
//Debug.Log(animNow);

//直接赋值加载AC
gameObject.GetComponent<Animator>().runtimeAnimatorController=animNow;

}

// Update is called once per frame
void Update ()

{

//var controll = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath("Assets/Resources/ac1");

}

}

对于其它方法,我就不介绍了。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: