import System.IO; //dat tat ca cac tai nguyen vao trong mot thu muc //Assets/Ten_thumuc: trong vi du nay ta dung thu muc "MakeAssetBundle " //www.3din.com.vn
function Start() { var path: String = AssetDatabase.GetAssetPath(Selection.activeObject); Debug.Log("Selected Folder: " + path); if (path.Length != 0) { path = path.Replace("Assets/", ""); var fileEntries: Array = Directory.GetFiles(Application.dataPath+"/"+path);
for(var fileName: String in fileEntries) { var filePath: String = fileName.Replace(" ", "/"); filePath = filePath.Replace("\\","/"); var index: int = filePath.LastIndexOf("/"); filePath = filePath.Substring(index); Debug.Log(filePath); var localPath: String = "Assets/" + path; if (index > 0) localPath += filePath; var t: Object = AssetDatabase.LoadMainAssetAtPath(localPath); if (t != null) { Debug.Log(t.name); var bundlePath: String = "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); } } } } |
var www = WWW ("http://www.3din.com.vn/cube_prefab.unity3d"); yield www; if (www.error != null){ Debug.Log(www.error); }else{ // Get the designated main asset and instantiate it. var assetB = www.assetBundle.Load("cube"); var obj = Instantiate (assetB, transform.position, Quaternion.identity); } |
Ý kiến bạn đọc [ 0 ]
Ý kiến của bạn