static void _PrepareResources(string outPath, bool forUpdate) { bool zipLua = false; bool pertty = true; bool copyManifest = false; if (forUpdate) { zipLua = true; pertty = false; copyManifest = true; } XManifest.Instance.Load(Path.Combine(XManifest.resOutputPath, XManifest.name).Replace("\\", "/")); int total = 0; total += (XManifest.Instance.GetPacks() as Dictionary <string, XManifest.Pack>).Count; total += (XManifest.Instance.GetFiles() as Dictionary <string, XManifest.File>).Count; int current = 0; //copy bundles string bundleSrcPath = XManifest.resOutputPath.Replace("\\", "/"); string bundleAimPath = Path.Combine(outPath, AssetBundleManager.bundleFolder); if (Directory.Exists(bundleAimPath)) { Directory.Delete(bundleAimPath, true); } Directory.CreateDirectory(bundleAimPath); foreach (KeyValuePair <string, XManifest.Pack> item in XManifest.Instance.GetPacks()) { XManifest.Pack pack = item.Value; File.Copy(Path.Combine(bundleSrcPath, pack.name), Path.Combine(bundleAimPath, Path.ChangeExtension(pack.name, null) + "." + pack.checksum), true); EditorUtility.DisplayProgressBar("Prepare Bundle Resource", pack.name, current++ / (float)total); } // copy luas string luaScrPath = Defines.LuaByteCodeOutPath; string luaAimPath = Path.Combine(outPath, LuaFilePicker.fileFolder); if (Directory.Exists(luaAimPath)) { Directory.Delete(luaAimPath, true); } Directory.CreateDirectory(luaAimPath); foreach (KeyValuePair <string, XManifest.File> item in XManifest.Instance.GetFiles()) { XManifest.File file = item.Value; var srcName = Path.Combine(luaScrPath, file.name); var srcPath = Path.Combine(luaScrPath, file.name); var aimName = Path.ChangeExtension(file.name, null) + "." + file.checksum; var aimPath = Path.Combine(luaAimPath, aimName); File.Copy(srcPath, aimPath, true); EditorUtility.DisplayProgressBar("Prepare Bundle Resource", file.name, current++ / (float)total); } // copy/save manifest if (copyManifest) { uint manifestChecksum = 0; uint manifestSize = 0; var manifestAimPath = Path.Combine(outPath, XManifest.name); //XManifest.Instance.Save(manifestAimPath, pertty); XManifestSave(manifestAimPath, pertty); GetFileInfo(manifestAimPath, out manifestChecksum, out manifestSize); string destName = manifestAimPath + ("." + manifestChecksum); File.Copy(manifestAimPath, destName); } else { //XManifest.Instance.Save(Path.Combine(outPath, XManifest.name), pertty); XManifestSave(Path.Combine(outPath, XManifest.name), pertty); } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); }
public static void GenerateFileAllocationTable(BuildTarget buildTarget) { string targetName = XManifest.GetPlatformFolder(buildTarget); string bundlePath = assetBundleOutputPath; EditorUtility.DisplayProgressBar("Generate Manifest", "loading bundle manifest", 1 / 2); AssetBundle bundle = AssetBundle.LoadFromFile(Path.Combine(bundlePath, targetName)); if (bundle == null) { Debug.LogError("Build Resrouce First."); EditorUtility.ClearProgressBar(); return; } XManifest.Instance.Clear(); try { string manifestSavePath = XManifest.manifestOutputPath; // gen packs AssetBundleManifest manifest = bundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); string[] bundles = manifest.GetAllAssetBundles(); EditorUtility.DisplayProgressBar("Generate Manifest", "compute bundle hash", 0); for (int i = 0; i < bundles.Length; i++) { string bundleName = bundles[i]; XManifest.Pack pack = new XManifest.Pack(); pack.name = bundleName; uint checksum = 0; uint size = 0; GetFileInfo(Path.Combine(bundlePath, bundleName), out checksum, out size); pack.checksum = checksum; pack.size = size; pack.location = XManifest.Location.Streaming; //pack.preloadType = XManifest.PreloadType.Loading; List <string> dependencies = new List <string>(manifest.GetAllDependencies(bundleName)); dependencies.Remove(bundleName); pack.dependencies = dependencies.ToArray(); XManifest.Instance.Add(pack); foreach (string file in AssetDatabase.GetAssetPathsFromAssetBundle(bundleName)) { if (Path.GetExtension(file) == ".unity") // gen scenes { XManifest.Scene scene = new XManifest.Scene(); scene.name = Path.GetFileNameWithoutExtension(file); scene.bundle = bundleName; XManifest.Instance.Add(scene); } else if (Path.GetExtension(file) == ".spriteatlas") // gen sporitepack { var name = Path.GetFileNameWithoutExtension(file); if (XManifest.Instance.GetSpritePack(name) != null) { throw new System.Exception("can't have mutip spriteatlas named:" + file); } List <string> allPackable = new List <string>(); var sa = AssetDatabase.LoadAssetAtPath <UnityEngine.U2D.SpriteAtlas>(file); var textureNameMap = new Dictionary <string, bool>(); foreach (var pa in UnityEditor.U2D.SpriteAtlasExtensions.GetPackables(sa)) { var assetPath = AssetDatabase.GetAssetPath(pa.GetInstanceID()); assetPath = assetPath.Replace(Defines.AssetBundleSourcePath + "/", null); assetPath = Path.ChangeExtension(assetPath, null); allPackable.Add(assetPath); } XManifest.SpritePack spritePack = new XManifest.SpritePack(); spritePack.name = name; spritePack.packable = allPackable.ToArray(); var realName = file.Replace(Defines.AssetBundleSourcePath + "/", null).ToLower().Replace("\\", "/"); if (System.IO.Path.HasExtension(realName)) { realName = System.IO.Path.ChangeExtension(realName, null); } spritePack.realName = realName; XManifest.Instance.Add(spritePack); } } EditorUtility.DisplayProgressBar("Generate Manifest", "compute bundle hash", i / (float)bundles.Length); } // record luas List <string> luaFiles = new List <string>(); GetAllFile(new DirectoryInfo(Defines.LuaByteCodeOutPath), luaFiles); foreach (string fileName in luaFiles) { string name = Path.GetFileNameWithoutExtension(fileName); if (!XManifest.Instance.Exists(name)) { XManifest.File file = new XManifest.File(); file.name = name; file.location = XManifest.Location.Streaming; uint checksum = 0; uint size = 0; GetFileInfo(fileName, out checksum, out size); file.checksum = checksum; file.size = size; XManifest.Instance.Add(file); } else { Debug.LogError("[GenerateFileAllocationTable] repeat name:" + name); } } // gen rules BundleNameHelper.initPackRules(); foreach (BundlePackRule rule in BundleNameHelper.rules) { XManifest.Instance.AddBundleRule(rule); } GameConfig.VersionInfo version = new GameConfig.VersionInfo(VersionCode); XManifestSave(manifestSavePath, true); Debug.Log("[GenerateFileAllocationTable] Mainfest 生成成功:" + manifestSavePath); } catch (System.Exception e) { Debug.LogException(e); } EditorUtility.DisplayProgressBar("Generate Manifest", "success!", 1.0f); bundle.Unload(true); EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); }