是不是AB总需要手动制作?AB包工具不好用?我们来一起探讨吧,这一节我们先来制作怎么规划好AB文件的自动一键化制作AB的原始文件,其中包含的动画文件,材质文件,还有预制体。其实有一些功能我们是可以一键化自动生成的AB原始文件,例如动画,我们可以让美术做好带动画的fbx文件,我们读取fbx里面的动画生成动画文件 并且设置需要打成AB的名字和变体(variant)或者叫后缀
/// <summary>
/// 生成动画 和动画ab包设置
/// </summary>
static void ProduceAni()
{
if (Directory.Exists(PathConfig.PathAni))
{
DirectoryInfo directoryInfo = new DirectoryInfo(PathConfig.PathAni);
// FileInfo[] files = directoryInfo.GetFiles("*");
FileInfo[] files = directoryInfo.GetFiles("*", SearchOption.AllDirectories);
// Debug.Log(files.Length);
for (int i = 0; i < files.Length; i++)
{
//忽略关联文件
if (files[i].Name.EndsWith(".meta") || files[i].Name.EndsWith(".mesh"))
{
continue;
}
Debug.Log("文件名:" + files[i].Name);
Debug.Log("文件绝对路径:" + files[i].FullName);
Debug.Log("文件所在目录:" + files[i].DirectoryName);
if (files[i].Name.EndsWith(".FBX") || files[i].Name.EndsWith(".fbx"))
{
var filesString = files[i].Name.Split('.')[0];
var path = PathConfig.PathResourcesAni + "/" + filesString;
// 创建文件夹
if (Directory.Exists(path + "_ani"))
{
Debug.Log("preafab所谓在的位置:" + path);
Debug.Log("preafab:" + path + "/" + filesString + ".prefab");
Debug.Log(path);
Directory.Delete(path + "_ani", recursive: true);
File.Delete(path + "_ani" + ".meta");
}
Directory.CreateDirectory(path + "_ani");
Debug.Log(PathConfig.PathAni + "/" +
filesString); // AnimatorController animatorController = AnimatorController.CreateAnimatorControllerAtPath("Assets/Test.controller");
AnimatorController animatorController =
AnimatorController.CreateAnimatorControllerAtPath(path + "_ani" + "/" + filesString +
"_ani" + ".controller");
Debug.Log(File.Exists(PathConfig.PathAni + "/" + files[i].Name));
Debug.Log(AssetDatabase.LoadAssetAtPath(PathConfig.PathAni + "/" + files[i].Name,
typeof(AnimationClip)) as AnimationClip);
AnimationClip src = AssetDatabase.LoadAssetAtPath(PathConfig.PathAni + "/" + files[i].Name,
typeof(AnimationClip)) as AnimationClip;