public static void BuildAssetBundlesBatch() { // Choose the output path according to the build target. string outputPath = Path.Combine(kAssetBundlesOutputPath, BaseLoader.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } string [] args = System.Environment.GetCommandLineArgs(); Debug.Log("ARGS:" + args[9]); int startRatio = int.Parse(args[9]); int endRatio = int.Parse(args[10]); string [] allAssetBundleNames = AssetDatabase.GetAllAssetBundleNames(); int counter = allAssetBundleNames.Length * startRatio / 100; int counter_end = allAssetBundleNames.Length * endRatio / 100; Debug.Log("Build " + counter + "/" + allAssetBundleNames.Length + " -> " + (counter_end - 1) + "/" + allAssetBundleNames.Length); AssetBundleBuild[] buildMap = new AssetBundleBuild[counter_end - counter]; int num = 0; for (int i = counter; i < counter_end; i++) { string abname = allAssetBundleNames[i]; buildMap[num].assetBundleName = abname; buildMap[num].assetNames = AssetDatabase.GetAssetPathsFromAssetBundle(abname); num++; } BuildPipeline.BuildAssetBundles(outputPath, buildMap, 0, EditorUserBuildSettings.activeBuildTarget); }
static void CopyAssetBundlesTo(string outputPath) { // Clear streaming assets folder. FileUtil.DeleteFileOrDirectory(Application.streamingAssetsPath); Directory.CreateDirectory(outputPath); string outputFolder = BaseLoader.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget); // Setup the source folder for assetbundles. var source = Path.Combine(Path.Combine(System.Environment.CurrentDirectory, kAssetBundlesOutputPath), outputFolder); if (!System.IO.Directory.Exists(source)) { Debug.Log("No assetBundle output folder, try to build the assetBundles first."); } // Setup the destination folder for assetbundles. var destination = System.IO.Path.Combine(outputPath, outputFolder); if (System.IO.Directory.Exists(destination)) { FileUtil.DeleteFileOrDirectory(destination); } FileUtil.CopyFileOrDirectory(source, destination); }
public static void DeleteOldAsset() { string outputPath = Path.Combine(kAssetBundlesOutputPath, BaseLoader.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)); if (Directory.Exists(outputPath)) { Directory.Delete(outputPath, true); } }
public static void SetRepogitory(string _url) { PatchURL = _url; #if UNITY_EDITOR PatchURL = PatchURL + BaseLoader.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget) + "/"; #else PatchURL = PatchURL + BaseLoader.GetPlatformFolderForAssetBundles(Application.platform) + "/"; #endif AssetBundleManager.BaseDownloadingURL = PatchURL + CommonPatcherData.lastVersionRepo + "/"; }
public static void BuildAssetBundles() { // Choose the output path according to the build target. string outputPath = Path.Combine(kAssetBundlesOutputPath, BaseLoader.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } BuildPipeline.BuildAssetBundles(outputPath, 0, EditorUserBuildSettings.activeBuildTarget); }
public static void BuildAssetBundles() { string outputPath = Path.Combine(kAssetBundlesOutputPath, BaseLoader.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } BuildPipeline.BuildAssetBundles(outputPath, 0, EditorUserBuildSettings.activeBuildTarget); Md5MenuItems.GenMd5(); }
// Use this for initialization void Start() { scenarioDetails = new List <ScenarioDetail>(); scenesFolderPath = Path.Combine(Path.Combine("AssetBundles", BaseLoader.GetPlatformFolderForAssetBundles(Application.platform)), "scenario"); sceneBundlePaths = Directory.GetFiles(Path.Combine(Application.streamingAssetsPath, scenesFolderPath)) .Where(file => file.Substring(file.Length - 8) != "manifest" && file.Substring(file.Length - 4) != "meta").ToList(); int i = 0; foreach (var sceneBundlePath in sceneBundlePaths) { var sceneListItem = (GameObject)Instantiate(listItemPrefab, transform, false); var path = sceneBundlePath.Replace('\\', '/').Split('/'); var sceneName = path[path.Length - 1]; var detail = ScenarioParser.ParseScenario(sceneName); sceneListItem.transform.Find("Text").GetComponent <Text>().text = detail.Phobia + " : " + detail.Name; scenarioDetails.Add(detail); //The first scene is selected by default if (i == 0) { selectedSceneName = sceneName; } int currentIndex = i; sceneListItem.GetComponent <Button>().onClick.AddListener(() => { selectedSceneName = sceneName; detailPanel.ShowScenarioDetail(scenarioDetails[currentIndex]); }); i++; } if (scenarioDetails.Count > 0) { detailPanel.ShowScenarioDetail(scenarioDetails[0]); } }
// Use this for initialization protected virtual void Start() { scenesFolderPath = Path.Combine(Path.Combine("AssetBundles", BaseLoader.GetPlatformFolderForAssetBundles(Application.platform)), "safezones"); safezonePaths = Directory.GetFiles(Path.Combine(Application.streamingAssetsPath, scenesFolderPath)) .Where(file => file.Substring(file.Length - 8) != "manifest" && file.Substring(file.Length - 4) != "meta").ToList(); int i = 0; foreach (var safezonePath in safezonePaths) { var sceneListItem = (GameObject)Instantiate(listItemPrefab, transform, false); var pathArray = safezonePath.Replace('\\', '/').Split('/'); var safezoneName = pathArray[pathArray.Length - 1]; sceneListItem.transform.Find("Text").GetComponent <Text>().text = safezoneName; sceneListItem.GetComponent <Button>().onClick.AddListener(() => { SelectSafezone(safezoneName); }); i++; } }
public static void BuildAssetBundles(BuildAssetBundleOptions buildOptions = BuildAssetBundleOptions.None) { // 暗号化AssetBundle生成処理 if (isAESCryption) { Debug.Log("AES Cryption Building."); BuildAssetBundlesForAES(buildOptions); return; } else { Debug.Log("Standard Building."); } // Choose the output path according to the build target. string outputPath = Path.Combine(kAssetBundlesOutputPath, BaseLoader.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } BuildPipeline.BuildAssetBundles(outputPath, buildOptions, EditorUserBuildSettings.activeBuildTarget); }
/// <summery> /// 暗号化AssetBundle生成 /// </summery> public static void BuildAssetBundlesForAES(BuildAssetBundleOptions buildOptions = BuildAssetBundleOptions.None) { // Resourcesから暗号化キーを取得 AESConfig config = Resources.Load <AESConfig>("AESConfig"); // ------------ // 暗号化情報が正しいか確認 if (config == null) { Debug.LogError("Dosen't find \"AESConfig.asset\"."); return; } else if (string.IsNullOrEmpty(config.Password) || string.IsNullOrEmpty(config.Salt)) { Debug.LogError("Please set AES Password and Salt. AES configuration menu is [AssetBundles/Open AES Config]"); return; } else if (config.Salt.Length < 8) { Debug.LogError("AES Salt is must over 8 chars."); return; } // ------------ // 一時ディレクトリ作成 string dirName = "____CryptingABs"; string tmpPath = "Assets/" + dirName; if (!Directory.Exists(tmpPath)) { // 作成 Directory.CreateDirectory(tmpPath); } // フォルダの中身が存在していた場合は削除 else if (Directory.GetFileSystemEntries(tmpPath).Length > 0) { DeleteTemporaryFiles(tmpPath, true); } // AssetBundleBuild 1回目 BuildPipeline.BuildAssetBundles(tmpPath, buildOptions, EditorUserBuildSettings.activeBuildTarget); // ------------ // 書き出されたAssetBundleに暗号化を施す処理 // 保存したファイル一覧を取得 string[] files = Directory.GetFiles(tmpPath); // AssetBundleのリネーム処理 foreach (string str in files) { // AssetBundle本体に.bytes拡張子を付与しつつ、不要ファイルを削除 if (!(str.Contains(".manifest") || str.Contains(".meta"))) { // ディレクトリ名と同じファイル (____CryptingABs) だった場合は削除 string[] s = str.Split('/'); if (s[s.Length - 1] == dirName) { File.Delete(str); } else { File.Move(str, str + ".bytes"); // リネーム } } else { File.Delete(str); // 削除 } } // 再度、AssetBundle全ファイルのパスを取得 files = Directory.GetFiles(tmpPath); // ------------ // 書き出されたAssetBundleを暗号化して、再度暗号化済みAssetBundleを書き出す処理 AssetBundleBuild[] buildMap = new AssetBundleBuild[files.Length]; // 暗号化処理実行 for (int i = 0; i < files.Length; i++) { string file = files[i]; // 暗号化符号作成 string[] s = file.Split('/'); string cryptoSign = Path.Combine(tmpPath, AssetBundleManager.CRYPTO_SIGN + s[s.Length - 1]); StreamWriter sign = File.CreateText(cryptoSign); sign.Close(); byte[] plain = File.ReadAllBytes(file); // byteデータ取得 byte[] encData = AESCryption.Encryption(plain); // 暗号化 File.WriteAllBytes(file, encData); // 暗号化済みAssetBundleを書き出す // BuildMap設定 string[] str = file.Split(new Char[] { '/', '.' }); string name = str[str.Length - 2]; Debug.Log("BuildTargetAsset : " + name); buildMap[i].assetBundleName = name; buildMap[i].assetNames = new string[] { file, cryptoSign }; } // 一度プロジェクトをリセットして、暗号化したAssetBundleを反映させる AssetDatabase.Refresh(); // 暗号化済みAssetBundle保存パス string absOutputPath = Path.Combine(kAssetBundlesOutputPath, BaseLoader.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)); if (!Directory.Exists(absOutputPath)) { Directory.CreateDirectory(absOutputPath); } // AssetBundleBuild 2回目 BuildPipeline.BuildAssetBundles(absOutputPath, buildMap, buildOptions, EditorUserBuildSettings.activeBuildTarget); // 一時ファイルの削除 DeleteTemporaryFiles(tmpPath); // 完了 AssetDatabase.Refresh(); Debug.Log("Successful creation of encrypted AssetBundles."); }
//[MenuItem(kBuildAssetBundlesMenu)] public static void BuildAssetBundles(BuildTarget buildTarget, List <string> buildingAssets = null) { Debug.Log("Start Build Assetbundles"); //ProjectBuilder.SetBuildVersion_fromEnvVariable(); // Choose the output path according to the build target. string outputPath = Path.Combine(kAssetBundlesOutputPath, BaseLoader.GetPlatformFolderForAssetBundles(buildTarget)); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } string[] existingFilesPath = Directory.GetFiles(outputPath); List <FileInfo> existingFiles = new List <FileInfo>(); if (existingFilesPath != null) { for (int i = 0; i < existingFilesPath.Length; ++i) { FileInfo eachFile = new FileInfo(existingFilesPath[i]); existingFiles.Add(eachFile); } } //total assets string[] bundles = AssetDatabase.GetAllAssetBundleNames(); AssetBundleManifest totalManifest; //BuildPipeline.BuildAssetBundles (outputPath, 0, EditorUserBuildSettings.activeBuildTarget); if (buildingAssets == null || buildingAssets.Count <= 0) { totalManifest = BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.None, buildTarget); // hash값 유지? } else if (bundles != null) { List <AssetBundleBuild> tempListBundles = new List <AssetBundleBuild>(); for (int i = 0; i < buildingAssets.Count; ++i) { bool isRightAssetName = false; for (int j = 0; j < bundles.Length; ++j) { if (bundles[j].Equals(buildingAssets[i]) == true) { isRightAssetName = true; break; } } if (isRightAssetName == true) { AssetBundleBuild newStructInfo = new AssetBundleBuild(); newStructInfo.assetBundleName = buildingAssets[i]; newStructInfo.assetNames = AssetDatabase.GetAssetPathsFromAssetBundle(buildingAssets[i]); tempListBundles.Add(newStructInfo); } } AssetBundleBuild[] arrBundles = tempListBundles.ToArray(); totalManifest = BuildPipeline.BuildAssetBundles(outputPath, arrBundles, BuildAssetBundleOptions.None, buildTarget); } else { Debug.LogError("There is no assetbundle to build"); return; } string deviceManifestPath = Path.Combine(outputPath, buildTarget.ToString()); uint deviceCRC = 0; BuildPipeline.GetCRCForAssetBundle(deviceManifestPath, out deviceCRC); FileInfo totalManiFile = new FileInfo(deviceManifestPath); //total manifest stAssetInfo totalAssetManifest = new stAssetInfo(); totalAssetManifest.Name = buildTarget.ToString(); totalAssetManifest.CRC = deviceCRC; totalAssetManifest.FileSize = totalManiFile.Length; //each assets string[] BuiltBundles = totalManifest.GetAllAssetBundles(); List <stAssetInfo> listAssetInfo = new List <stAssetInfo>(); listAssetInfo.Add(totalAssetManifest); if (BuiltBundles == null) { Debug.LogError("bundles is null"); return; } int invalidCount = 0; for (int i = 0; i < BuiltBundles.Length; ++i) { //어셋 파일 존재 검증 string targetPath = Path.Combine(outputPath, BuiltBundles[i]); if (File.Exists(targetPath) == false) { invalidCount++; Debug.LogError(BuiltBundles[i] + " is not exist"); } } if (invalidCount > 0) { return; } string buildTargetBundle = buildTarget.ToString(); string buildTargetManifest = buildTargetBundle + ".manifest"; IEnumerable <FileInfo> deleteTarget = existingFiles.Where( (fileInfo) => { if (fileInfo.Name.Equals(buildTargetBundle) || fileInfo.Name.Equals(buildTargetManifest) || fileInfo.Name.Equals("patch.xml")) { return(false); } IEnumerable <string> foundBundles = from bundleName in bundles where (fileInfo.Name.Equals(bundleName) || fileInfo.Name.Equals(StringUtils.Append(bundleName, ".manifest"))) select bundleName; if (foundBundles.Count() > 0) { return(false); } return(true); } ); Debug.Log("Start Delete non-asset files"); foreach (FileInfo deleteFile in deleteTarget) { Debug.Log("Deleting " + deleteFile.Name + " ......"); deleteFile.Delete(); } for (int i = 0; i < bundles.Length; ++i) { stAssetInfo newInfo = new stAssetInfo(); string bundleName = bundles[i]; string targetPath = Path.Combine(outputPath, bundleName); uint crc = 0; if (BuildPipeline.GetCRCForAssetBundle(targetPath, out crc) == true) { FileInfo assetFile = new FileInfo(targetPath); newInfo.Name = bundleName; newInfo.CRC = crc; newInfo.FileSize = assetFile.Length; listAssetInfo.Add(newInfo); } } VersionXML.MakeVersionFile(deviceCRC, outputPath, listAssetInfo); Debug.Log("End Build Assetbundles"); }