unity load .fbx and image files automatically

step1: copy .fbx and image files into Assets/

step2: copy MyEditorScript.cs into Assets/Editor

step3: cd to the exe folder-->   Unity.exe -quit -batchmode -executeMethod MyEditorScript.MyMethod

using UnityEngine;
using UnityEditor;
using System.IO;


public class MyEditorScript {
[@MenuItem("Asset/Build AssetBundles From Directory of Files")]
static void MyMethod () {
   ExportAssetBundles(); //BuildAssetBundlesFromDirectory
    //...
}
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);
Debug.Log(filePath);
string localPath = "Assets/" + path;
if (index > 0)
localPath += filePath;
Object t = AssetDatabase.LoadMainAssetAtPath(localPath);
if (t != null) {
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);
}
}
}
}
}

猜你喜欢

转载自blog.csdn.net/kong5461/article/details/23667595
今日推荐