private bool StoreAssetBundleListToStorage(AssetBundleList list) { var listStr = JsonUtility.ToJson(list); var result = _autoyaFilePersistence.Update(AssetBundlesSettings.ASSETBUNDLES_LIST_STORED_DOMAIN, list.identity, listStr); return(result); }
public IEnumerator LoadListFromWeb(string listDownloadPath) { var downloaded = false; var downloader = new HTTPConnection(); AssetBundleList listObj = null; yield return(downloader.Get( "loadListFromWeb", null, listDownloadPath, (conId, code, respHeaders, data) => { downloaded = true; listObj = JsonUtility.FromJson <AssetBundleList>(data); }, (conId, code, reason, respHeaders) => { Debug.LogError("failed conId:" + conId + " code:" + code + " reason:" + reason); } )); yield return(WaitUntil( () => downloaded, () => { throw new TimeoutException("failed to download list."); } )); yield return(listObj); }
/** [シングルトン]インスタンス。作成。 */ public static void CreateInstance() { if (s_instance == null) { s_instance = new AssetBundleList(); } }
private CurrentUsingBundleCondition GetCurrentAssetBundleUsingCondition(AssetBundleList newList) { // check version of new list and current stored list. var currentList = _assetBundleLoader.GetAssetBundleListByIdentity(newList.identity); if (currentList.version != newList.version) { // check using assets are changed or not. var newBundleCrcs = newList.assetBundles.ToDictionary(bundle => bundle.bundleName, bundle => bundle.crc); var oldBundleCrcs = currentList.assetBundles.ToDictionary(bundle => bundle.bundleName, bundle => bundle.crc); var changedUsingBundleNames = new List<string>(); foreach (var oldBundleCrcItem in oldBundleCrcs) { var bundleName = oldBundleCrcItem.Key; var bundleCrc = oldBundleCrcItem.Value; if (newBundleCrcs.ContainsKey(bundleName)) { if (newBundleCrcs[bundleName] != bundleCrc) { // crc changed = assetBundle is updated. // is using now? if (_assetBundleLoader.IsAssetBundleCachedOnMemory(bundleName)) { /* changed assetBundle is using now. */ changedUsingBundleNames.Add(bundleName); } } } else { // in new list, current using assetBundle is not exists. // nothing to do. but detected. } } if (changedUsingBundleNames.Any()) { // using assetBundle is updated in new list. return CurrentUsingBundleCondition.UsingAssetsAreChanged; } else { // no using && change of assetBundles are detected. return CurrentUsingBundleCondition.NoUsingAssetsChanged; } } // list version is not changed. return CurrentUsingBundleCondition.AlreadyUpdated; }
IEnumerator Start() { var LIST_DOWNLOAD_URL = "https://raw.githubusercontent.com/sassembla/Autoya/master/AssetBundles/main_assets/OSX/1.0.0/main_assets.json"; var ASSET_NAME = "Assets/AutoyaTests/RuntimeData/AssetBundles/MainResources/textureName.png"; // Download AssetBundle List from web. var listDownloader = new AssetBundleListDownloader(); AssetBundleList list = null; var cor = listDownloader.DownloadAssetBundleList( LIST_DOWNLOAD_URL, (url, newList) => { list = newList; }, (code, reason, status) => { Debug.LogError("list download error, code:" + code + " reason:" + reason); } ); while (cor.MoveNext()) { yield return(null); } // Load Asset from your AssetBundle. var loader = new AssetBundleLoader( bundleName => { var path = "https://raw.githubusercontent.com/sassembla/Autoya/master/AssetBundles/" + list.identity + "/" + list.target + "/" + list.version + "/"; return(path); } ); // set list to AssetBundleLoader. loader.UpdateAssetBundleList(list); var loadCor = loader.LoadAsset <Texture2D>( ASSET_NAME, (name, tex) => { Debug.Log("asset loaded! tex:" + tex); }, (name, error, reason, status) => { Debug.LogError("asset load failed. error:" + error + " reason:" + reason); } ); while (loadCor.MoveNext()) { yield return(null); } }
/** [シングルトン]インスタンス。削除。 */ public static void DeleteInstance() { if (s_instance != null) { s_instance.Delete(); s_instance = null; } }
public static void AssetBundle_UpdateList(string path, AssetBundleList list) { // if (autoya == null) { // failed(); // } // if (Autoya.Auth_IsLoggedIn()) { // failed(); // } autoya._assetBundleLoader = new AssetBundleLoader(path, list, autoya.assetBundleRequestHeaderDelegate, autoya.httpResponseHandlingDelegate); // 仮のリストの更新API。実際に使うとしたら、内部から。 }
/* * * [MenuItem ("Tools/DataMaker/Test")] * static void Open () * { * DisplayWizard<AssetBundleListObjectMaker> ("test"); * } * * void OnWizardUpdate () * { * //isValid = !string.IsNullOrEmpty(asssetBundleLoadURL); * } * * * void OnWizardCreate () * { * PrizeOfferSettingData loadSettingData = CreateInstance<PrizeOfferSettingData> (); * * loadSettingData.loadURL = "Test"; * * //Directory.CreateDirectory("Assets/AssetExcelDataResources/Resources"); * //string path = "Assets/AssetExcelDataResources/Resources/PrizeOfferSettingData.asset"; * * //Directory.CreateDirectory("Assets/AssetExcelDataResources/Resources"); * string path = m_strLoadURL + source_path; * * * AssetDatabase.CreateAsset (loadSettingData, path); * AssetDatabase.ImportAsset (path); * EditorUtility.UnloadUnusedAssets (); * } */ public static void MakeObject() { Debug.LogWarning("MakeObject :"); AssetBundleList assetBundleListData = CreateInstance <AssetBundleList> (); string path = m_strLoadURL + source_path; // AssetDatabase.CreateAsset(assetBundleListData, path); AssetDatabase.ImportAsset(path); EditorUtility.UnloadUnusedAssets(); AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive); }
public IEnumerator LoadSceneFromAssetBundle() { var listCor = LoadListFromWeb(sceneListPath); yield return(listCor); bundleList = listCor.Current as AssetBundleList; loader = new AssetBundleLoader(identity => sceneAbDlPath + "1.0.0/"); loader.UpdateAssetBundleList(bundleList); var cleaned = loader.CleanCachedAssetBundles(); if (!cleaned) { Fail("clean cache failed."); } var done = false; var sceneName = string.Empty; // シーンをロードする。 yield return(loader.LoadScene( "Assets/AutoyaTests/RuntimeData/bundledScene.unity", LoadSceneMode.Additive, loadedSceneName => { sceneName = loadedSceneName; done = true; }, (loadFailedSceneName, error, reason, status) => { Fail("failed to load scene, loadFailedSceneName:" + loadFailedSceneName + " error:" + error + " reason:" + reason); } )); True(done); var cor = SceneManager.UnloadSceneAsync(SceneManager.GetSceneByPath(sceneName)); while (!cor.isDone) { yield return(null); } }
public IEnumerator Setup() { var listCor = LoadListFromWeb(abListPath); yield return(listCor); bundleList = listCor.Current as AssetBundleList; loader = new AssetBundleLoader(identity => abDlPath + "1.0.0/"); loader.UpdateAssetBundleList(bundleList); var cleaned = loader.CleanCachedAssetBundles(); if (!cleaned) { Fail("clean cache failed."); } }
private void ReadyLoaderAndPreloader(AssetBundleList list) { // initialize/reload AssetBundleLoader. { if (_assetBundleLoader == null) { AssetBundleLoader.HttpResponseHandlingDelegate httpResponseHandlingDel = (p1, p2, p3, p4, p5, p6, p7) => { httpResponseHandlingDelegate(p1, p2, p3, p4, p5, p6, p7); }; AssetBundleLoader.AssetBundleGetRequestHeaderDelegate assetBundleGetRequestHeaderDel = (p1, p2) => { return(assetBundleGetRequestHeaderDelegate(p1, p2)); }; _assetBundleLoader = new AssetBundleLoader(OnAssetBundleDownloadUrlRequired, assetBundleGetRequestHeaderDel, httpResponseHandlingDel); } _assetBundleLoader.UpdateAssetBundleList(list); } // initialize AssetBundlePreloader. { if (_assetBundlePreloader != null) { // do nothing. } else { AssetBundlePreloader.HttpResponseHandlingDelegate httpResponseHandlingDel = (p1, p2, p3, p4, p5, p6, p7) => { httpResponseHandlingDelegate(p1, p2, p3, p4, p5, p6, p7); }; AssetBundlePreloader.PreloadListGetRequestHeaderDelegate assetBundleGetRequestHeaderDel = (p1, p2) => { return(assetBundlePreloadListGetRequestHeaderDelegate(p1, p2)); }; _assetBundlePreloader = new AssetBundlePreloader(assetBundleGetRequestHeaderDel, httpResponseHandlingDel); } } }
private void OnUpdatingListReceived(AssetBundleList newList) { var assetUsingCondition = GetCurrentAssetBundleUsingCondition(newList); if (ShouldUpdateToNewAssetBundleList(assetUsingCondition)) { var result = StoreAssetBundleListToStorage(newList); if (result) { // update runtime manifest. { var newListIdentity = newList.identity; var runtimeManifest = Autoya.Manifest_LoadRuntimeManifest(); foreach (var resInfo in runtimeManifest.resourceInfos) { if (resInfo.listIdentity == newListIdentity) { resInfo.listVersion = newList.version; break; } } Autoya.Manifest_UpdateRuntimeManifest(runtimeManifest); } ReadyLoaderAndPreloader(newList); // finish downloading new assetBundleList. newListDownloaderState = NewListDownloaderState.Ready; return; } // failed to store new assetBundleList. } // finish downloading new assetBundleList. newListDownloaderState = NewListDownloaderState.Ready; return; }
private void OnUpdatingListReceived(AssetBundleList newList) { var assetUsingCondition = GetCurrentAssetBundleUsingCondition(newList); if (ShouldUpdateToNewAssetBundleList(assetUsingCondition)) { var result = StoreAssetBundleListToStorage(newList); if (result) { // update runtime manifest. set "resVersion" to downloaded version. { var runtimeManifest = Autoya.Manifest_LoadRuntimeManifest(); runtimeManifest.resVersion = newList.version; Autoya.Manifest_UpdateRuntimeManifest(runtimeManifest); } _currentAssetBundleList = newList; // discard postponed cache. _postponedNewAssetBundleList = null; // finish downloading new assetBundleList. newListDownloaderState = NewListDownloaderState.Ready; return; } // failed to store new assetBundleList. } // store on memory as postponed. // list is not updated actually. _postponedNewAssetBundleList = newList; // finish downloading new assetBundleList. newListDownloaderState = NewListDownloaderState.Ready; return; }
private IEnumerator OnUpdatingListReceived(AssetBundleList newList) { var assetUsingCondition = GetCurrentAssetBundleUsingCondition(newList); var proceed = false; var done = false; ShouldUpdateToNewAssetBundleList( assetUsingCondition, () => { done = true; proceed = true; }, () => { done = true; proceed = false; } ); while (!done) { yield return(null); } if (!proceed) { yield break; } // store AssetBundleList and renew Loader and Preloader. var result = StoreAssetBundleListToStorage(newList); if (result) { // update AssetBundleList version. OnUpdateToNewAssetBundleList(newList.identity, newList.version); ReadyLoaderAndPreloader(newList); /* * start postprocess. */ var condition = GetCurrentAssetBundleUsingCondition(newList); var postProcessReady = false; OnAssetBundleListUpdated( condition, () => { postProcessReady = true; } ); while (!postProcessReady) { yield return(null); } yield break; } // failed to store new assetBundleList. var cor = OnNewAssetBundleListStoreFailed("failed to store new AssetBundleList to storage. maybe shortage of storage size."); while (cor.MoveNext()) { yield return(null); } // failed. fin. }
/** CoroutineMain */ public System.Collections.IEnumerator CoroutineMain(Fee.AssetBundleList.OnAssetBundleListCoroutine_CallBackInterface a_callback_interface, string a_assetbundle_name) { //result this.result = new ResultType(); { AssetBundleItem t_assetbundle_item = Fee.AssetBundleList.AssetBundleList.GetInstance().GetAssetBundleItem(a_assetbundle_name); if (t_assetbundle_item != null) { //成功。 this.result.assetbundle_item = t_assetbundle_item; yield break; } } PathItem t_pathitem = AssetBundleList.GetInstance().GetPathItem(a_assetbundle_name); if (t_pathitem == null) { //失敗。 this.result.errorstring = "Coroutine_LoadPathItemAssetBundleItem : Not Found Path : " + a_assetbundle_name; yield break; } //ダミーアセットバンドルの読み込み。 #if (UNITY_EDITOR) if (t_pathitem.assetbundle_pathtype == AssetBundlePathType.AssetsPathDummyAssetBundle) { string t_result_string = null; { Fee.File.Item t_item_dummy_assetbundle_json = Fee.File.File.GetInstance().RequestLoad(File.File.LoadRequestType.LoadAssetsPathTextFile, t_pathitem.assetbundle_path); if (t_item_dummy_assetbundle_json == null) { //失敗。 this.result.errorstring = "Coroutine_LoadPathItemAssetBundleItem : item_json = null : " + a_assetbundle_name; yield break; } do { if (a_callback_interface != null) { a_callback_interface.OnAssetBundleListCoroutine(t_item_dummy_assetbundle_json.GetResultProgress()); } yield return(null); }while(t_item_dummy_assetbundle_json.IsBusy() == true); if (t_item_dummy_assetbundle_json.GetResultAssetType() == Asset.AssetType.Text) { t_result_string = t_item_dummy_assetbundle_json.GetResultAssetText(); } if (t_result_string == null) { //失敗。 this.result.errorstring = "Coroutine_LoadPathItemAssetBundleItem : result_string == null : " + a_assetbundle_name; yield break; } } //DummryAssetBundle Fee.AssetBundleList.DummryAssetBundle t_dummyassetbundle = Fee.JsonItem.Convert.JsonStringToObject <Fee.AssetBundleList.DummryAssetBundle>(t_result_string); if (t_dummyassetbundle == null) { //失敗。 this.result.errorstring = "Coroutine_LoadPathItemAssetBundleItem : dummyassetbundle = null : " + a_assetbundle_name; yield break; } AssetBundleItem t_assetbundle_item = new AssetBundleItem(t_dummyassetbundle, t_pathitem); //登録。 Fee.AssetBundleList.AssetBundleList.GetInstance().RegistAssetBundleItem(a_assetbundle_name, t_assetbundle_item); //成功。 this.result.assetbundle_item = t_assetbundle_item; yield break; } #endif //アセットバンドルの読み込み。 { //アセットバンドル。 Fee.Pattern.Progress t_progress = new Fee.Pattern.Progress(new float[] { 0.5f, 0.5f }); //アセットバンドルのバイナリ読み込み。 byte[] t_result_binary = null; { Fee.File.Item t_item_bianry = null; switch (t_pathitem.assetbundle_pathtype) { #if (UNITY_EDITOR) case AssetBundlePathType.AssetsPathAssetBundle: { //アセットフォルダにあるアセットバンドルの相対パス。 t_item_bianry = Fee.File.File.GetInstance().RequestLoad(File.File.LoadRequestType.LoadAssetsPathBinaryFile, t_pathitem.assetbundle_path); } break; #endif case AssetBundlePathType.UrlAssetBundle: { //URL。 t_item_bianry = Fee.File.File.GetInstance().RequestLoad(File.File.LoadRequestType.LoadUrlBinaryFile, t_pathitem.assetbundle_path); } break; case AssetBundlePathType.StreamingAssetsAssetBundle: { //ストリーミングアセット。 t_item_bianry = Fee.File.File.GetInstance().RequestLoad(File.File.LoadRequestType.LoadStreamingAssetsBinaryFile, t_pathitem.assetbundle_path); } break; case AssetBundlePathType.LocalAssetBundle: { //ローカル。 t_item_bianry = Fee.File.File.GetInstance().RequestLoad(File.File.LoadRequestType.LoadLocalBinaryFile, t_pathitem.assetbundle_path); } break; case AssetBundlePathType.FullPathAssetBundle: { //フルパス。 t_item_bianry = Fee.File.File.GetInstance().RequestLoad(File.File.LoadRequestType.LoadFullPathBinaryFile, t_pathitem.assetbundle_path); } break; default: { //失敗。 this.result.errorstring = "Coroutine_LoadPathItemAssetBundleItem : PathTypeError : " + a_assetbundle_name; yield break; } break; } if (t_item_bianry == null) { //失敗。 this.result.errorstring = "Coroutine_LoadPathItemAssetBundleItem : item_bianry = null : " + a_assetbundle_name; yield break; } do { //■ステップ0。 if (a_callback_interface != null) { t_progress.SetStep((int)Progress_MainStep.Progress_MainStep_0_LoadBinary, 0, 1); a_callback_interface.OnAssetBundleListCoroutine(t_progress.CalcProgress(t_item_bianry.GetResultProgress())); } yield return(null); }while(t_item_bianry.IsBusy() == true); if (t_item_bianry.GetResultAssetType() == Asset.AssetType.Binary) { t_result_binary = t_item_bianry.GetResultAssetBinary(); } if (t_result_binary == null) { //失敗。 this.result.errorstring = "Coroutine_LoadPathItemAssetBundleItem : result_binary == null : " + a_assetbundle_name; yield break; } else { System.Collections.Generic.Dictionary <string, string> t_response_header = t_item_bianry.GetResultResponseHeader(); if (t_response_header != null) { string t_response_code; if (t_item_bianry.GetResultResponseHeader().TryGetValue(Fee.File.Config.RESPONSECODE_KEY, out t_response_code) == true) { if (t_response_code != "200") { //失敗。 this.result.errorstring = "Coroutine_LoadPathItemAssetBundleItem : t_response_code = " + t_response_code; yield break; } } } } } //バイナリーのアセットバンドル化。 { UnityEngine.AssetBundleCreateRequest t_request = null; //LoadFromMemoryAsync try{ t_request = UnityEngine.AssetBundle.LoadFromMemoryAsync(t_result_binary); }catch (System.Exception t_exception) { Tool.DebugReThrow(t_exception); } if (t_request == null) { this.result.errorstring = "Coroutine_LoadPathItemAssetBundleItem : request == null : " + a_assetbundle_name; yield break; } do { //■ステップ1。 if (a_callback_interface != null) { t_progress.SetStep((int)Progress_MainStep.Progress_MainStep_1_LoadFromMemoryAsync, 0, 1); a_callback_interface.OnAssetBundleListCoroutine(t_progress.CalcProgress(t_request.progress)); } yield return(null); }while(t_request.isDone == false); if (t_request.assetBundle == null) { //失敗。 this.result.errorstring = "Coroutine_LoadPathItemAssetBundleItem : assetbundle == null : " + a_assetbundle_name; yield break; } { AssetBundleItem t_assetbundle_item = new AssetBundleItem(t_request.assetBundle, t_pathitem); #if (UNITY_EDITOR) { UnityEngine.Object[] t_object = t_request.assetBundle.LoadAllAssets(); for (int ii = 0; ii < t_object.Length; ii++) { Tool.Log(a_assetbundle_name, t_object[ii].name); } } #endif //登録。 Fee.AssetBundleList.AssetBundleList.GetInstance().RegistAssetBundleItem(a_assetbundle_name, t_assetbundle_item); //成功。 this.result.assetbundle_item = t_assetbundle_item; yield break; } } } }
public IEnumerator LoadCrcMismatchedBundle() { // change specific bumdle's crc to incorrect one. for (var i = 0; i < bundleList.assetBundles.Length; i++) { var bundle = bundleList.assetBundles[i]; if (bundle.bundleName == "texturename") { bundleList.assetBundles[i] = new AssetBundleInfo(bundle.bundleName, bundle.assetNames, bundle.dependsBundleNames, 1, bundle.hash, bundle.size); } } loader = new AssetBundleLoader(identity => abDlPath + "1.0.0/"); loader.UpdateAssetBundleList(bundleList); // intentional fail. { var done = false; yield return(loader.LoadAsset( "Assets/AutoyaTests/RuntimeData/AssetBundles/MainResources/textureName.png", (string assetName, Texture2D texAsset) => { // do nothing. }, (assetName, failEnum, reason, status) => { True(failEnum == AssetBundleLoadError.CrcMismatched, "error is not crc mismatched. failEnum:" + failEnum); done = true; } )); yield return(WaitUntil( () => done, () => { throw new TimeoutException("failed to wait crc mismatch."); } )); } // refresh list. var listCor = LoadListFromWeb(abListPath); yield return(listCor); bundleList = listCor.Current as AssetBundleList; loader.UpdateAssetBundleList(bundleList); // retry. { Texture2D tex = null; var done = false; yield return(loader.LoadAsset( "Assets/AutoyaTests/RuntimeData/AssetBundles/MainResources/textureName.png", (string assetName, Texture2D texAsset) => { tex = texAsset; done = true; }, (assetName, failEnum, reason, status) => { Debug.Log("fail, failEnum:" + failEnum + " reason:" + reason); Fail("fail, failEnum:" + failEnum + " reason:" + reason); done = true; } )); yield return(WaitUntil( () => done, () => { throw new TimeoutException("failed to wait crc mismatch."); } )); True(tex != null, "tex is null."); } }
/* * DoPostprocess() is called when build performed. * @param [in] reports collection of AssetBundleBuildReport from each BundleBuilders. */ public void DoPostprocess(IEnumerable <AssetBundleBuildReport> buildReports, IEnumerable <ExportReport> exportReports) { // リスト名とversionから、出力するlistの名称を決め、ファイルを移動させる。 // なんらか対象の設定の把握ができるといいんだけど、exportPathからとるか。 var sampleExportArray = exportReports.ToArray(); if (sampleExportArray == null || sampleExportArray.Length == 0) { // no exports found. return; } // pick first exporter only. if (!sampleExportArray[0].ExportedItems.Any()) { // empty exports. return; } Debug.Log("sampleExport destination:" + sampleExportArray[0].ExportedItems[0].destination); Debug.Log("currentTargetPlatform:" + EditorUserBuildSettings.activeBuildTarget + " export platform str is:" + BuildTargetUtility.TargetToAssetBundlePlatformName(EditorUserBuildSettings.activeBuildTarget)); /* * ここは大変まどろっこしいことをしていて、 * exporterからexportPathを取得できないので、exportされたAssetから"現在のプラットフォームString/現在のプラットフォームString" というパス/ファイル名になるmanifestファイルを探し出し、 * そのパスの直上のディレクトリ名がexportPathの最下位のフォルダ名になるので、それを取得しリスト名として使用している。 */ var exportPlatformStr = BuildTargetUtility.TargetToAssetBundlePlatformName(EditorUserBuildSettings.activeBuildTarget); var platformDelimiter = exportPlatformStr + "/" + exportPlatformStr + ".manifest";// XPlatform/XPlatform.manifest var rootManifestEntry = sampleExportArray[0].ExportedItems.Where(p => p.destination.Contains(platformDelimiter)).FirstOrDefault(); if (rootManifestEntry == null) { Debug.Log("no exported root manifest with :" + platformDelimiter + " found."); ///もしここに来ているようなら、何かAssetGraphToolsの設定間違えの可能性があります。 ///元から入っているmain_assetsのAssetGraphToolの設定を見てください。 return; } var wholeExportFolderName = rootManifestEntry.destination.Substring(0, rootManifestEntry.destination.IndexOf(platformDelimiter) - 1 /*remove last / */); var settingFilePath = wholeExportFolderName + ".json"; if (!File.Exists(settingFilePath)) { Debug.Log("no setting file exists:" + settingFilePath); return; } var settingFileData = File.ReadAllBytes(settingFilePath); if (settingFileData.Length == 0) { Debug.Log("setting file is empty:" + settingFilePath + " need to define ListProfile class parameters."); return; } var settingProfile = JsonUtility.FromJson <ListProfile>(Encoding.UTF8.GetString(settingFileData)); var listIdentity = settingProfile.identity; var listVersion = settingProfile.version; var rootManifestPath = rootManifestEntry.destination; Debug.Log("generating AssetBundleList. rootManifestPath:" + rootManifestPath + " generate list identity:" + listIdentity + " version:" + listVersion); var targetDirectory = FileController.PathCombine(wholeExportFolderName, exportPlatformStr, listVersion); // check if version folder is exists. if (Directory.Exists(targetDirectory)) { Debug.Log("same version files are already exists. list identity:" + listIdentity + " version:" + listVersion + " path:" + targetDirectory + " need to delete directory."); return; // Directory.Delete(targetDirectory, true); } // create version directory under exportPlatformStr. // then copy necessary files. { Directory.CreateDirectory(targetDirectory); foreach (var exportReport in exportReports) { var items = exportReport.ExportedItems; foreach (var item in items) { var currentPath = item.destination; // skip root manifest and root file. if (currentPath.Contains(exportPlatformStr + "/" + exportPlatformStr)) { continue; } var fileName = Path.GetFileName(currentPath); if (fileName == listIdentity + ".json") { throw new Exception("generated AssetBundle name:" + listIdentity + ".json is overlapped with list name. please change assetBundle name, extension or list identity."); } var dirPath = Path.GetDirectoryName(currentPath); var destPath = FileController.PathCombine(dirPath, listVersion, fileName); File.Copy(currentPath, destPath); } } } // root manifest から全てのbundleの依存関係を取り出す + 各bundleのManifestから詳細を取得する。 { var bundleAndDependencies = new List <AssetBundleInfo>(); /* * load root manifest file and get assetBundle names and dependencies. */ using (var sr = new StreamReader(rootManifestPath)) { // read root manifest file. { var rootYaml = new YamlStream(); rootYaml.Load(sr); var rootMapping = (YamlMappingNode)rootYaml.Documents[0].RootNode; foreach (var root_item in rootMapping) { var rootKey = ((YamlScalarNode)root_item.Key).Value; switch (rootKey) { case "ManifestFileVersion": { // Debug.LogError("ManifestFileVersion:" + ((YamlScalarNode)root_item.Value).Value); break; } case "AssetBundleManifest": { var assetBundleManifestMapping = (YamlMappingNode)root_item.Value; foreach (var assetBundleManifestMapping_item in assetBundleManifestMapping) { var manifestKey = ((YamlScalarNode)assetBundleManifestMapping_item.Key).Value; switch (manifestKey) { case "AssetBundleInfos": { var manifestInfoSeq = (YamlMappingNode)assetBundleManifestMapping_item.Value; foreach (var manifestInfo_item in manifestInfoSeq) { var bundleInfo = new AssetBundleInfo(); var bundleInfoMapping = (YamlMappingNode)manifestInfo_item.Value; foreach (var info_item in bundleInfoMapping) { var infoKey = ((YamlScalarNode)info_item.Key).Value; switch (infoKey) { case "Name": { var name = ((YamlScalarNode)info_item.Value).Value; // Debug.LogError("name:" + name); bundleInfo.bundleName = name; break; } case "Dependencies": { var dependenciesMapping = (YamlMappingNode)info_item.Value; foreach (var dependency_item in dependenciesMapping) { var dependentBundleName = ((YamlScalarNode)dependency_item.Value).Value; // Debug.LogError("dependentBundleName:" + dependentBundleName); } var dependentBundleNames = dependenciesMapping.Select(t => ((YamlScalarNode)t.Value).Value).ToArray(); bundleInfo.dependsBundleNames = dependentBundleNames; break; } } } bundleAndDependencies.Add(bundleInfo); } break; } } } break; } } } } } // create assetBundleList. var assetBundleInfos = new List <AssetBundleInfo>(); /* * load each assetBundle info from bundle manifests. */ foreach (var bundleAndDependencie in bundleAndDependencies) { var targetBundleName = bundleAndDependencie.bundleName; var newAssetBundleInfo = new AssetBundleInfo(); newAssetBundleInfo.bundleName = targetBundleName; newAssetBundleInfo.dependsBundleNames = bundleAndDependencie.dependsBundleNames; using (var sr = new StreamReader(FileController.PathCombine(wholeExportFolderName, exportPlatformStr, targetBundleName + ".manifest"))) { var rootYaml = new YamlStream(); rootYaml.Load(sr); var rootMapping = (YamlMappingNode)rootYaml.Documents[0].RootNode; foreach (var root_item in rootMapping) { var rootKey = ((YamlScalarNode)root_item.Key).Value; switch (rootKey) { case "CRC": { var crc = Convert.ToUInt32(((YamlScalarNode)root_item.Value).Value); // Debug.LogError("crc:" + crc); newAssetBundleInfo.crc = crc; break; } case "Assets": { var assetNamesSeq = (YamlSequenceNode)root_item.Value; var assetNames = assetNamesSeq.Select(n => ((YamlScalarNode)n).Value).ToArray(); // foreach (var assetName in assetNames) { // Debug.LogError("assetName:" + assetName); // } newAssetBundleInfo.assetNames = assetNames; break; } case "Hashes": { var hashMapping = (YamlMappingNode)root_item.Value; foreach (var hash_item in hashMapping) { var hashKey = ((YamlScalarNode)hash_item.Key).Value; switch (hashKey) { case "AssetFileHash": { var assetHashMapping = (YamlMappingNode)hash_item.Value; foreach (var assetHash_item in assetHashMapping) { var assetHashKey = ((YamlScalarNode)assetHash_item.Key).Value; switch (assetHashKey) { case "Hash": { var hashStr = ((YamlScalarNode)assetHash_item.Value).Value; // Debug.LogError("hashStr:" + hashStr); newAssetBundleInfo.hash = hashStr; break; } } } break; } } } break; } } } // set size. newAssetBundleInfo.size = new FileInfo(FileController.PathCombine(wholeExportFolderName, exportPlatformStr, targetBundleName)).Length; // Debug.LogError("newAssetBundleInfo.size:" + newAssetBundleInfo.size); assetBundleInfos.Add(newAssetBundleInfo); } } var assetBundleList = new AssetBundleList(listIdentity, exportPlatformStr, listVersion, assetBundleInfos.ToArray()); var str = JsonUtility.ToJson(assetBundleList, true); var listOutputPaht = FileController.PathCombine(wholeExportFolderName, exportPlatformStr, listVersion, listIdentity + ".json"); using (var sw = new StreamWriter(listOutputPaht)) { sw.WriteLine(str); } } }
IEnumerator Start() { Debug.LogFormat("[GameManager]:Start()"); DontDestroyOnLoad(gameObject); Version = Application.version; UIManager.Instance().Initialize(frameConfigs); UIManager.Instance().OpenFrame <LoadingFrame>(null, 7); //加载线上版本 yield return(AssetBundleManager.Instance().DownLoadTextFile(gameConfig.gameResourcesServer, Function.getPlatformString(), "gameConfig.txt", null, onLoadGameConfigSucceed)); if (configs.ContainsKey(@"version")) { Version = configs[@"version"]; } Debug.LogFormat("[version]:{0}", Version); AssetBundleList remoteAssetBundleList = null; yield return(AssetBundleManager.Instance().DownLoadAssetBundle(gameConfig.gameResourcesServer, Version, "filemd5", (AssetBundle bundle) => { remoteAssetBundleList = bundle.LoadAsset <AssetBundleList>("AssetBundleMd5List.asset"); if (null != remoteAssetBundleList) { AssetBundleList = remoteAssetBundleList; Debug.LogFormat("download assetbundle succeed ..."); } else { Debug.LogFormat("download assetbundle failed ..."); } }, () => { Debug.LogFormat("download assetbundle failed ..."); })); if (null == AssetBundleList) { Debug.LogErrorFormat("load AssetBundleList failed ..."); yield break; } AssetBundleList.Make(); bool isDone = false; AssetBundleManager.Instance().AddDownLoadActionListener("baseBundle", Version, AssetBundleList.baseAssetBundles, OnDownLoadProcess, () => { AssetBundleManager.Instance().RemoveDownLoadActionListener("baseBundle", OnDownLoadProcess); isDone = true; Debug.LogFormat("DownLoad Finish ..."); }); AssetBundleManager.Instance().DownLoadAssetBundles(gameConfig.gameResourcesServer, Version, AssetBundleList.baseAssetBundles, AssetBundleList.baseKeys); while (!isDone) { yield return(null); } bool succeed = true; yield return(AssetBundleManager.Instance().LoadAssetBundleManifest(gameConfig.gameResourcesServer, Version, null, () => { succeed = false; })); if (!succeed) { Debug.LogErrorFormat("Load AssetBundleManifest Failed ..."); yield break; } var storepath = Function.getAssetBundlePersistentPath(Version, string.Empty, true); yield return(AssetBundleManager.Instance().LoadAssetBundlesEnumerator(storepath, AssetBundleList.baseAssetBundles, null, null, (float value) => { EventManager.Instance().SendEvent(Event.Event.EventLoadingProgress, value * 0.50f + 0.50f); })); EventManager.Instance().SendEvent(Event.Event.EventEndLoading); }
/* * { * "ManifestFileVersion": "0", * "CRC": "2462514955", * "AssetBundleManifest": { * "AssetBundleInfos": { * "Info_0": { * "Name": "bundlename", * "Dependencies": {} * }, * "Info_1": { * "Name": "dependsbundlename", * "Dependencies": {// うーん複数階層持つことがあり得るのか〜〜きっちーな。このレイヤーは紛れもなく辞書なんだ。 * "Dependency_0": "bundlename" * } * }, * "Info_2": { * "Name": "dependsbundlename2", * "Dependencies": { * "Dependency_0": "bundlename" * } * }, * "Info_3": { * "Name": "nestedprefab", * "Dependencies": { * "Dependency_0": "dependsbundlename" * } * }, * "Info_4": { * "Name": "updatable", * "Dependencies": { * "Dependency_0": "bundlename" * } * } * } * } * } * */ public void MakeList() { var targetOSStr = targetOS.ToString(); if (!Directory.Exists(PATH_ASSETBUNDLES_EXPORTED)) { Debug.LogError("no directory found:" + PATH_ASSETBUNDLES_EXPORTED); return; } var platformPath = FileController.PathCombine(PATH_ASSETBUNDLES_EXPORTED, targetOSStr); if (!Directory.Exists(platformPath)) { Debug.LogError("no platform folder found:" + platformPath); return; } var assumedListFilePath = FileController.PathCombine(platformPath, "AssetBundles." + targetOSStr + "_" + version.Replace(".", "_") + ".json"); if (File.Exists(assumedListFilePath) && !shouldOverwrite) { Debug.LogError("same version file:" + assumedListFilePath + " is already exists."); return; } var bundleAndDependencies = new List <AssetBundleInfo>(); /* * load root manifest file and get assetBundle names and dependencies. */ using (var sr = new StreamReader(FileController.PathCombine(PATH_ASSETBUNDLES_EXPORTED, targetOSStr, targetOSStr + ".manifest"))) { // read root manifest file. { var rootYaml = new YamlStream(); rootYaml.Load(sr); var rootMapping = (YamlMappingNode)rootYaml.Documents[0].RootNode; foreach (var root_item in rootMapping) { var rootKey = ((YamlScalarNode)root_item.Key).Value; switch (rootKey) { case "ManifestFileVersion": { // Debug.LogError("ManifestFileVersion:" + ((YamlScalarNode)root_item.Value).Value); break; } case "AssetBundleManifest": { var assetBundleManifestMapping = (YamlMappingNode)root_item.Value; foreach (var assetBundleManifestMapping_item in assetBundleManifestMapping) { var manifestKey = ((YamlScalarNode)assetBundleManifestMapping_item.Key).Value; switch (manifestKey) { case "AssetBundleInfos": { var manifestInfoSeq = (YamlMappingNode)assetBundleManifestMapping_item.Value; foreach (var manifestInfo_item in manifestInfoSeq) { var bundleInfo = new AssetBundleInfo(); var bundleInfoMapping = (YamlMappingNode)manifestInfo_item.Value; foreach (var info_item in bundleInfoMapping) { var infoKey = ((YamlScalarNode)info_item.Key).Value; switch (infoKey) { case "Name": { var name = ((YamlScalarNode)info_item.Value).Value; // Debug.LogError("name:" + name); bundleInfo.bundleName = name; break; } case "Dependencies": { var dependenciesMapping = (YamlMappingNode)info_item.Value; foreach (var dependency_item in dependenciesMapping) { var dependentBundleName = ((YamlScalarNode)dependency_item.Value).Value; // Debug.LogError("dependentBundleName:" + dependentBundleName); } var dependentBundleNames = dependenciesMapping.Select(t => ((YamlScalarNode)t.Value).Value).ToArray(); bundleInfo.dependsBundleNames = dependentBundleNames; break; } } } bundleAndDependencies.Add(bundleInfo); } break; } } } break; } } } } } var assetBundleInfos = new List <AssetBundleInfo>(); /* * load each assetBundle info from bundle manifests. */ foreach (var bundleAndDependencie in bundleAndDependencies) { var targetBundleName = bundleAndDependencie.bundleName; var newAssetBundleInfo = new AssetBundleInfo(); newAssetBundleInfo.bundleName = targetBundleName; newAssetBundleInfo.dependsBundleNames = bundleAndDependencie.dependsBundleNames; using (var sr = new StreamReader(FileController.PathCombine(PATH_ASSETBUNDLES_EXPORTED, targetOSStr, targetBundleName + ".manifest"))) { var rootYaml = new YamlStream(); rootYaml.Load(sr); var rootMapping = (YamlMappingNode)rootYaml.Documents[0].RootNode; foreach (var root_item in rootMapping) { var rootKey = ((YamlScalarNode)root_item.Key).Value; switch (rootKey) { case "CRC": { var crc = Convert.ToUInt32(((YamlScalarNode)root_item.Value).Value); // Debug.LogError("crc:" + crc); newAssetBundleInfo.crc = crc; break; } case "Assets": { var assetNamesSeq = (YamlSequenceNode)root_item.Value; var assetNames = assetNamesSeq.Select(n => ((YamlScalarNode)n).Value).ToArray(); // foreach (var assetName in assetNames) { // Debug.LogError("assetName:" + assetName); // } newAssetBundleInfo.assetNames = assetNames; break; } case "Hashes": { var hashMapping = (YamlMappingNode)root_item.Value; foreach (var hash_item in hashMapping) { var hashKey = ((YamlScalarNode)hash_item.Key).Value; switch (hashKey) { case "AssetFileHash": { var assetHashMapping = (YamlMappingNode)hash_item.Value; foreach (var assetHash_item in assetHashMapping) { var assetHashKey = ((YamlScalarNode)assetHash_item.Key).Value; switch (assetHashKey) { case "Hash": { var hashStr = ((YamlScalarNode)assetHash_item.Value).Value; // Debug.LogError("hashStr:" + hashStr); newAssetBundleInfo.hash = hashStr; break; } } } break; } } } break; } } } // set size. newAssetBundleInfo.size = new FileInfo(FileController.PathCombine(PATH_ASSETBUNDLES_EXPORTED, targetOSStr, targetBundleName)).Length; // Debug.LogError("newAssetBundleInfo.size:" + newAssetBundleInfo.size); assetBundleInfos.Add(newAssetBundleInfo); } } var assetBundleList = new AssetBundleList(targetOSStr, version, assetBundleInfos.ToArray()); var str = JsonUtility.ToJson(assetBundleList, true); var listExportPath = FileController.PathCombine(PATH_ASSETBUNDLES_EXPORTED, targetOSStr, "AssetBundles." + targetOSStr + "_" + version.Replace(".", "_") + ".json"); /* * write out to file. * "AssetBundles/OS/AssetBundles.OS_v_e_r.json". */ using (var sw = new StreamWriter(listExportPath)) { sw.WriteLine(str); } Debug.Log("list exported at:" + listExportPath); }
/* * DoPostprocess() is called when build performed. * @param [in] reports collection of AssetBundleBuildReport from each BundleBuilders. */ public void DoPostprocess(IEnumerable <AssetBundleBuildReport> buildReports, IEnumerable <ExportReport> exportReports) { // リスト名とversionから、出力するlistの名称を決め、ファイルを移動させる。 // なんらか対象の設定の把握ができるといいんだけど、exportPathからとるか。 var sampleExportArray = exportReports.ToArray(); if (sampleExportArray == null || sampleExportArray.Length == 0) { // no exports found. return; } // pick first exporter only. if (!sampleExportArray[0].ExportedItems.Any()) { // empty exports. return; } var exportPlatformStr = BuildTargetUtility.TargetToAssetBundlePlatformName(EditorUserBuildSettings.activeBuildTarget); var platformDelimiter = exportPlatformStr + "/" + exportPlatformStr + ".manifest";// XPlatform/XPlatform.manifest var rootManifestEntry = sampleExportArray[0].ExportedItems.Where(p => p.destination.Contains(platformDelimiter)).FirstOrDefault(); if (rootManifestEntry == null) { Debug.Log("no exported root manifest with :" + platformDelimiter + " found."); return; } // full path for export base path. var wholeExportFolderPath = rootManifestEntry.destination.Substring(0, rootManifestEntry.destination.IndexOf(platformDelimiter) - 1 /*remove last / */); var graphName = new DirectoryInfo(wholeExportFolderPath).Name; var settingFilePath = EditVersionJson(graphName); var settingFileData = string.Empty; using (var sr = new StreamReader(settingFilePath)) { settingFileData = sr.ReadToEnd(); } var settingProfile = JsonUtility.FromJson <ListProfile>(settingFileData); var listIdentity = settingProfile.identity; var listVersion = settingProfile.version; var rootManifestPath = rootManifestEntry.destination; Debug.Log("generating AssetBundleList. rootManifestPath:" + rootManifestPath + " generate list identity:" + listIdentity + " version:" + listVersion); var targetDirectory = FileController.PathCombine(wholeExportFolderPath, exportPlatformStr, listVersion); // check if version folder is exists. if (Directory.Exists(targetDirectory)) { Debug.Log("same version files are already exists. list identity:" + listIdentity + " version:" + listVersion + " path:" + targetDirectory + " need to delete directory or modify list version. for editing list version, open Window > Autoya > Open AssetBundleListVersionEditor. "); return; } // create version directory under exportPlatformStr. // then copy necessary files. { Directory.CreateDirectory(targetDirectory); foreach (var exportReport in exportReports) { var items = exportReport.ExportedItems; foreach (var item in items) { var currentPath = item.destination; // skip root manifest and root file. if (currentPath.Contains(exportPlatformStr + "/" + exportPlatformStr)) { continue; } // skip manifest file. if (currentPath.EndsWith(".manifest")) { continue; } var fileName = Path.GetFileName(currentPath); if (fileName == listIdentity + ".json") { throw new Exception("generated AssetBundle name:" + listIdentity + ".json is overlapped with list name. please change assetBundle name, extension or list identity."); } var dirPath = Path.GetDirectoryName(currentPath); var destPath = FileController.PathCombine(dirPath, listVersion, fileName); File.Copy(currentPath, destPath); } } } // root manifest から全てのbundleの依存関係を取り出す + 各bundleのManifestから詳細を取得する。 { var bundleAndDependencies = new List <AssetBundleInfo>(); /* * load root manifest file and get assetBundle names and dependencies. */ using (var sr = new StreamReader(rootManifestPath)) { // read root manifest file. { var rootYaml = new YamlStream(); rootYaml.Load(sr); var rootMapping = (YamlMappingNode)rootYaml.Documents[0].RootNode; foreach (var root_item in rootMapping) { var rootKey = ((YamlScalarNode)root_item.Key).Value; switch (rootKey) { case "ManifestFileVersion": { // Debug.LogError("ManifestFileVersion:" + ((YamlScalarNode)root_item.Value).Value); break; } case "AssetBundleManifest": { var assetBundleManifestMapping = (YamlMappingNode)root_item.Value; foreach (var assetBundleManifestMapping_item in assetBundleManifestMapping) { var manifestKey = ((YamlScalarNode)assetBundleManifestMapping_item.Key).Value; switch (manifestKey) { case "AssetBundleInfos": { var manifestInfoSeq = (YamlMappingNode)assetBundleManifestMapping_item.Value; foreach (var manifestInfo_item in manifestInfoSeq) { var bundleInfo = new AssetBundleInfo(); var bundleInfoMapping = (YamlMappingNode)manifestInfo_item.Value; foreach (var info_item in bundleInfoMapping) { var infoKey = ((YamlScalarNode)info_item.Key).Value; switch (infoKey) { case "Name": { var name = ((YamlScalarNode)info_item.Value).Value; // Debug.LogError("name:" + name); bundleInfo.bundleName = name; break; } case "Dependencies": { var dependenciesMapping = (YamlMappingNode)info_item.Value; foreach (var dependency_item in dependenciesMapping) { var dependentBundleName = ((YamlScalarNode)dependency_item.Value).Value; // Debug.LogError("dependentBundleName:" + dependentBundleName); } var dependentBundleNames = dependenciesMapping.Select(t => ((YamlScalarNode)t.Value).Value).ToArray(); bundleInfo.dependsBundleNames = dependentBundleNames; break; } } } bundleAndDependencies.Add(bundleInfo); } break; } } } break; } } } } } // create assetBundleList. var assetBundleInfos = new List <AssetBundleInfo>(); var classIdSet = new HashSet <int>(); /* * load each assetBundle info from bundle manifests. */ foreach (var bundleAndDependencie in bundleAndDependencies) { var targetBundleName = bundleAndDependencie.bundleName; var newAssetBundleInfo = new AssetBundleInfo(); newAssetBundleInfo.bundleName = targetBundleName; newAssetBundleInfo.dependsBundleNames = bundleAndDependencie.dependsBundleNames; using (var sr = new StreamReader(FileController.PathCombine(wholeExportFolderPath, exportPlatformStr, targetBundleName + ".manifest"))) { var rootYaml = new YamlStream(); rootYaml.Load(sr); var rootMapping = (YamlMappingNode)rootYaml.Documents[0].RootNode; foreach (var root_item in rootMapping) { var rootKey = ((YamlScalarNode)root_item.Key).Value; switch (rootKey) { case "CRC": { var crc = Convert.ToUInt32(((YamlScalarNode)root_item.Value).Value); // Debug.LogError("crc:" + crc); newAssetBundleInfo.crc = crc; break; } case "Assets": { var assetNamesSeq = (YamlSequenceNode)root_item.Value; var assetNames = assetNamesSeq.Select(n => ((YamlScalarNode)n).Value).ToArray(); // foreach (var assetName in assetNames) { // Debug.LogError("assetName:" + assetName); // } newAssetBundleInfo.assetNames = assetNames; break; } case "Hashes": { var hashMapping = (YamlMappingNode)root_item.Value; foreach (var hash_item in hashMapping) { var hashKey = ((YamlScalarNode)hash_item.Key).Value; switch (hashKey) { case "AssetFileHash": { var assetHashMapping = (YamlMappingNode)hash_item.Value; foreach (var assetHash_item in assetHashMapping) { var assetHashKey = ((YamlScalarNode)assetHash_item.Key).Value; switch (assetHashKey) { case "Hash": { var hashStr = ((YamlScalarNode)assetHash_item.Value).Value; // Debug.LogError("hashStr:" + hashStr); newAssetBundleInfo.hash = hashStr; break; } } } break; } } } break; } case "ClassTypes": { var seq = (YamlSequenceNode)root_item.Value; foreach (var iSeq in seq) { var innerMap = (YamlMappingNode)iSeq; foreach (var map in innerMap) { switch ((string)map.Key) { case "Class": { classIdSet.Add(Convert.ToInt32((string)map.Value)); break; } } } } break; } default: { // ignore. break; } } } // set size. newAssetBundleInfo.size = new FileInfo(FileController.PathCombine(wholeExportFolderPath, exportPlatformStr, targetBundleName)).Length; // Debug.LogError("newAssetBundleInfo.size:" + newAssetBundleInfo.size); assetBundleInfos.Add(newAssetBundleInfo); } } var assetBundleList = new AssetBundleList(listIdentity, exportPlatformStr, listVersion, assetBundleInfos.ToArray()); var str = JsonUtility.ToJson(assetBundleList, true); var listOutputPath = FileController.PathCombine(wholeExportFolderPath, exportPlatformStr, listVersion, listIdentity + ".json"); using (var sw = new StreamWriter(listOutputPath)) { sw.WriteLine(str); } // generate Link.xml LinkXMLGenerator.ExportLinkXMLWithUsingClassIds(Application.dataPath, classIdSet.ToArray()); } }
public void MakeList() { var targetOSStr = targetOS.ToString(); if (!Directory.Exists(PATH_ASSETBUNDLES_EXPORTED)) { Debug.LogError("no directory found:" + PATH_ASSETBUNDLES_EXPORTED); return; } var platformPath = FileController.PathCombine(PATH_ASSETBUNDLES_EXPORTED, targetOSStr); if (!Directory.Exists(platformPath)) { Debug.LogError("no platform folder found:" + platformPath); return; } var assumedListFilePath = FileController.PathCombine(platformPath, "AssetBundles." + targetOSStr + "_" + version.Replace(".", "_") + ".json"); if (File.Exists(assumedListFilePath) && !shouldOverwrite) { Debug.LogError("same version file:" + assumedListFilePath + " is already exists."); return; } var bundleAndDependencies = new List <AssetBundleInfo>(); /* * load root manifest file and get assetBundle names and dependencies. */ using (var sr = new StreamReader(FileController.PathCombine(PATH_ASSETBUNDLES_EXPORTED, targetOSStr, targetOSStr + ".manifest"))) { var rootManifest = sr.ReadToEnd(); var deserializer = new DeserializerBuilder().Build(); var yamlObject = deserializer.Deserialize(new StringReader(rootManifest)); var serializer = new SerializerBuilder() .JsonCompatible() .Build(); var json = serializer.Serialize(yamlObject); var rootManifestHashTable = json.HashtableFromJson(); /* * C#でUnity JsonUtilityが読めるような型を作るには、manifestの型情報は汚すぎる。 * よって、Unityに同梱されているMiniJsonを使って、manifestをyaml -> json -> objectへと変換する。 */ foreach (var has in rootManifestHashTable) { if (has.Key == "AssetBundleManifest") { var manifestVal = has.Value as Dictionary <string, object>; foreach (var k in manifestVal) { if (k.Key == "AssetBundleInfos") { var infoDict = k.Value as Dictionary <string, object>; foreach (var l in infoDict) { var bundleInfo = new AssetBundleInfo(); /* * each assetBundle infos in root manifest are here. */ { var bundleKv = l.Value as Dictionary <string, object>; foreach (var m in bundleKv) { var bundleKvKey = m.Key; switch (bundleKvKey) { case "Name": { bundleInfo.bundleName = m.Value.ToString(); break; } case "Dependencies": { var dependenciesDict = m.Value as Dictionary <string, object>; var dependentBundleNames = dependenciesDict.Values.Select(t => t.ToString()).ToArray(); bundleInfo.dependsBundleNames = dependentBundleNames; break; } } } } bundleAndDependencies.Add(bundleInfo); } } } } } } var assetBundleInfos = new List <AssetBundleInfo>(); /* * load each assetBundle info from bundle manifests. */ foreach (var bundleAndDependencie in bundleAndDependencies) { var targetBundleName = bundleAndDependencie.bundleName; var newAssetBundleInfo = new AssetBundleInfo(); newAssetBundleInfo.bundleName = targetBundleName; newAssetBundleInfo.dependsBundleNames = bundleAndDependencie.dependsBundleNames; using (var sr = new StreamReader(FileController.PathCombine(PATH_ASSETBUNDLES_EXPORTED, targetOSStr, targetBundleName + ".manifest"))) { var bundleManifest = sr.ReadToEnd(); var deserializer = new DeserializerBuilder().Build(); var yamlObject = deserializer.Deserialize(new StringReader(bundleManifest)); var serializer = new SerializerBuilder().JsonCompatible().Build(); var json = serializer.Serialize(yamlObject); var bundleManifestHashTable = json.HashtableFromJson(); foreach (var k in bundleManifestHashTable) { switch (k.Key) { case "CRC": { var crc = Convert.ToUInt32(k.Value); newAssetBundleInfo.crc = crc; break; } case "Assets": { var assetNames = (k.Value as List <object>).Select(n => n.ToString()).ToArray(); newAssetBundleInfo.assetNames = assetNames; break; } case "Hashes": { var hashDict = k.Value as Dictionary <string, object>; foreach (var hashItem in hashDict) { if (hashItem.Key == "AssetFileHash") { var assetFileHashDict = hashItem.Value as Dictionary <string, object>; foreach (var assetFileHashItem in assetFileHashDict) { if (assetFileHashItem.Key == "Hash") { var hashStr = assetFileHashItem.Value.ToString(); newAssetBundleInfo.hash = hashStr; } } } } break; } } } assetBundleInfos.Add(newAssetBundleInfo); } } var assetBundleList = new AssetBundleList(targetOSStr, version, assetBundleInfos.ToArray()); var str = JsonUtility.ToJson(assetBundleList, true); var listExportPath = FileController.PathCombine(PATH_ASSETBUNDLES_EXPORTED, targetOSStr, "AssetBundles." + targetOSStr + "_" + version.Replace(".", "_") + ".json"); /* * write out to file. * "AssetBundles/OS/AssetBundles.OS_v_e_r.json". */ using (var sw = new StreamWriter(listExportPath)) { sw.WriteLine(str); } Debug.Log("list exported at:" + listExportPath); }