public static List <AssetBundleBuild> PackAssetBundles() { if (EditorApplication.isCompiling) { EditorUtility.DisplayDialog("", "Script is compiling, try again later.", "Yes"); return(null); } //Complie Lua File //LuaPackager.EncodeLuaFiles(); //Read The Build Config File Dictionary <string, int> config = new Dictionary <string, int>(); EditorUtil.ReadAssetConfig(config); //Get All AssetBundle File List <AssetBundleBuild> buildmap = new List <AssetBundleBuild>(); foreach (var pair in config) { BundleAction handler = allHandler[pair.Value - 1]; string path = EditorConst.ASSET_ROOT + pair.Key; if (Directory.Exists(path)) { var builds = handler.Invoke(path); buildmap.AddRange(builds as IEnumerable <AssetBundleBuild>); } } if (!Directory.Exists(OUTPUT_ROOT)) { Directory.CreateDirectory(OUTPUT_ROOT); } DoMakeAssetBundleAssetConfig(EditorConst.ASSET_CONFIG_PATH, buildmap); DoMakeAssetBundleLuaConfig(EditorConst.LUA_CONFIG_PATH, buildmap); AssetDatabase.Refresh(); //Begin Build PipeLine BuildPipeline.BuildAssetBundles(OUTPUT_ROOT, buildmap.ToArray(), BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); // Handle The Main Manifest string manifestPath = OUTPUT_ROOT + Path.GetFileName(Path.GetDirectoryName(OUTPUT_ROOT)); File.Copy(manifestPath, OUTPUT_ROOT + AB_MANIFEST + AB_EXTENSION, true); File.Delete(manifestPath); File.Copy(manifestPath + ".manifest", OUTPUT_ROOT + AB_MANIFEST + ".manifest", true); File.Delete(manifestPath + ".manifest"); AssetBundleBuild abb = new AssetBundleBuild(); abb.assetBundleName = AB_MANIFEST + AB_EXTENSION; buildmap.Add(abb); BuildVersionFile(VERSION_PATH, OUTPUT_ROOT, buildmap); AssetDatabase.Refresh(); UnityEngine.Debug.Log("Build assetbundles files finish!!"); return(buildmap); }
private static void BuildLua() { //Encode LuaPackager.EncodeLuaFiles(); //Build AB //Get Lua AssetBundle File //Read The Build Config File Dictionary <string, int> config = new Dictionary <string, int>(); EditorUtil.ReadAssetConfig(config); List <AssetBundleBuild> buildmap = new List <AssetBundleBuild>(); foreach (var pair in config) { BundleAction handler = allHandler[pair.Value - 1]; string path = EditorConst.ASSET_ROOT + pair.Key; if (Directory.Exists(path) && pair.Key.StartsWith("Lua")) { var builds = handler.Invoke(path); buildmap.AddRange(builds as IEnumerable <AssetBundleBuild>); } } DoMakeAssetBundleLuaConfig(EditorConst.LUA_CONFIG_PATH, buildmap); DoMakeAssetBundleAssetConfig(EditorConst.ASSET_CONFIG_PATH, buildmap); BuildPipeline.BuildAssetBundles(OUTPUT_ROOT, buildmap.ToArray(), BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); UnityEngine.Debug.Log("Build Lua Finish!!"); }
/// <summary> /// 包含Bundle是否需要加载判断,添加资源引用计数,并在尚未加载Bundle时,设置加载完成时回调 /// </summary> /// <param name="bundleIndex"></param> /// <param name="assetIndex"></param> private void LoadBundleForLoadAsset(int bundleIndex, int assetIndex) { BundleHandler bundleHandler = m_BundleHandlers[bundleIndex]; if (bundleHandler == null) { bundleHandler = m_BundleHandlerPool.Alloc(); bundleHandler.SetBundleIndex(bundleIndex); m_BundleHandlers[bundleIndex] = bundleHandler; } BundleAction bundleAction = bundleHandler.AddReference(); if (bundleAction == BundleAction.Load) { m_BundleActionRequests.Enqueue(new BundleActionRequest(bundleIndex, bundleAction)); MDebug.LogVerbose(LOG_TAG, $"Add load bundle action. Bundle:({m_BundleInfos[bundleIndex].BundleName}) Asset:({(AssetKey)assetIndex})"); } else if (bundleAction == BundleAction.Null) { // Dont need handle } else { MDebug.Assert(false, "AsestBundle", "Not support BundleAction: " + bundleAction); } bundleHandler.TryAddDependencyAsset(m_AssetHandlers[assetIndex]); }
/// <summary> /// 执行一个Action /// </summary> /// <returns>是否执行</returns> public bool TryExecuteAction(BundleAction bundleAction) { switch (bundleAction) { case BundleAction.Load: return(TryLoadBundle()); case BundleAction.Unload: return(TryUnloadBundle()); default: MDebug.Assert(false, LOG_TAG, "Not support BundleAction: " + bundleAction); return(false); } }
/// <summary> /// 减少指定Bundle包中的资源引用计数 /// </summary> /// <param name="bundleIndex"></param> private void RemoveAssetDependency(int bundleIndex, int assetIndex) { BundleHandler bundleHandler = m_BundleHandlers[bundleIndex]; if (bundleHandler != null) { BundleAction bundleAction = bundleHandler.RemoveReference(); if (bundleAction == BundleAction.Unload) { m_BundleActionRequests.Enqueue(new BundleActionRequest(bundleIndex, bundleAction)); MDebug.LogVerbose(LOG_TAG, $"Add remove bundle action. Bundle:({m_BundleInfos[bundleIndex].BundleName}) Asset:({(AssetKey)assetIndex})"); } else if (bundleAction == BundleAction.Null) { // Dont need handle } else { MDebug.Assert(false, "AsestBundle", "Not support BundleAction: " + bundleAction); } } }
public BundleActionRequest(int bundleIndex, BundleAction bundleAction) { BundleIndex = bundleIndex; BundleAction = bundleAction; }