public void ConvertDumpedAssets(Action <ErrorCodes> OnFinish = null) { if (!BuildAssetBundles(out AssetBundleManifest manifest)) { return; } CleanAssetBundleFolder(manifest.GetAllAssetBundles()); EditorCoroutineUtility.StartCoroutineOwnerless(VisualTests.TestConvertedAssets( env: env, OnFinish: (skippedAssetsCount) => { this.skippedAssets = skippedAssetsCount; if (this.skippedAssets > 0) { state.lastErrorCode = ErrorCodes.SOME_ASSET_BUNDLES_SKIPPED; } OnFinish?.Invoke(state.lastErrorCode); })); }
/// <summary> /// Generate asset bundles using a MappingPair list. /// /// This method will try to dump GLTF models, textures and buffers from the given mapping pair list, /// tag them for asset bundle building and finally build them. /// /// If the GLTF have external references of any texture/buffer of the same list, the references will be /// resolved correctly on the GLTF importer and then correctly converted to Asset Bundles references. /// /// Shader assets will be stripped from the generated bundles. /// </summary> /// <param name="rawContents">A list detailing assets to be dumped</param> /// <param name="OnFinish">End callback with the proper ErrorCode</param> public void Convert(ContentServerUtils.MappingPair[] rawContents, Action <ErrorCodes> OnFinish = null) { OnFinish += CleanAndExit; startTime = Time.realtimeSinceStartup; log.Info($"Conversion start... free space in disk: {PathUtils.GetFreeSpace()}"); InitializeDirectoryPaths(true); PopulateLowercaseMappings(rawContents); float timer = Time.realtimeSinceStartup; bool shouldGenerateAssetBundles = true; bool assetsAlreadyDumped = false; //TODO(Brian): Use async-await instead of Application.update void UpdateLoop() { try { //NOTE(Brian): We have to check this because the ImportAsset for GLTFs is not synchronous, and must execute some delayed calls // after the import asset finished. Therefore, we have to make sure those calls finished before continuing. if (!GLTFImporter.finishedImporting && Time.realtimeSinceStartup - timer < 60) { return; } env.assetDatabase.Refresh(); if (!assetsAlreadyDumped) { state.step = State.Step.DUMPING_ASSETS; shouldGenerateAssetBundles |= DumpAssets(rawContents); assetsAlreadyDumped = true; timer = Time.realtimeSinceStartup; if (settings.dumpOnly) { shouldGenerateAssetBundles = false; } //NOTE(Brian): return in order to wait for GLTFImporter.finishedImporting flag, as it will set asynchronously. return; } EditorApplication.update -= UpdateLoop; if (shouldGenerateAssetBundles) { AssetBundleManifest manifest; state.step = State.Step.BUILDING_ASSET_BUNDLES; if (BuildAssetBundles(out manifest)) { CleanAssetBundleFolder(manifest.GetAllAssetBundles()); state.lastErrorCode = ErrorCodes.SUCCESS; state.step = State.Step.FINISHED; } else { state.lastErrorCode = ErrorCodes.ASSET_BUNDLE_BUILD_FAIL; state.step = State.Step.FINISHED; } } else { state.lastErrorCode = ErrorCodes.SUCCESS; state.step = State.Step.FINISHED; } } catch (Exception e) { log.Error(e.Message + "\n" + e.StackTrace); state.lastErrorCode = ErrorCodes.UNDEFINED; state.step = State.Step.FINISHED; EditorApplication.update -= UpdateLoop; } EditorCoroutineUtility.StartCoroutineOwnerless(VisualTests.TestConvertedAssets( env: env, OnFinish: (skippedAssetsCount) => { this.skippedAssets = skippedAssetsCount; OnFinish?.Invoke(state.lastErrorCode); })); } EditorApplication.update += UpdateLoop; }