1.导出Unity3D格式资源:
把以下代码的脚本放到一个文件夹里面,选中该文件夹,再点击菜单栏上的按钮“Asset/Build AssetBundles From Directory of Files”,就成功转成Unity3D格式了。
以下是unity3d脚本
using UnityEngine;
using UnityEditor;
using System.IO;
public class BuildAssetBundlesFromDirectory {
[@MenuItem("Asset/Build AssetBundles From Directory of Files")]
static void ExportAssetBundles () {
// Get the selected directory
//获取选择的目录
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
Debug.Log("Selected Folder: " + path);
if (path.Length != 0) {
path = path.Replace("Assets/", "");
string [] fileEntries = Directory.GetFiles(Application.dataPath+"/"+path);
foreach(string fileName in fileEntries) {
string filePath = fileName.Replace("\\","/");
int index = filePath.LastIndexOf("/");
filePath = filePath.Substring(index+1);
Debug.Log("filePath:"+filePath);
string localPath = "Assets/" + path+"/";
if (index > 0)
localPath += filePath;
Object t = AssetDatabase.LoadMainAssetAtPath(localPath);
if (t != null) { //Unity3D教程手册:www.unitymanual.com
Debug.Log(t.name);
string bundlePath = "Assets/" + path + "/" + t.name + ".unity3d";
Debug.Log("Building bundle at: " + bundlePath);
// Build the resource file from the active selection.
//从激活的选择编译资源文件
BuildPipeline.BuildAssetBundle
(t, null, bundlePath, BuildAssetBundleOptions.CompleteAssets);
}
}
}
}
}
unity3d
本文介绍了一种将Unity3D项目的资源文件批量转换为Unity3D格式的方法。通过使用提供的脚本,开发者只需简单地选择文件夹并点击菜单项即可完成资源的打包工作。

2672

被折叠的 条评论
为什么被折叠?



