static IResPacker CreateResPacker(string filePath, EPackHandlerParam packHandlerParam) { filePath = filePath.Replace("\\", "/"); IResPacker resPacker = null; resPacker = GetResPacker(filePath); resPacker.SetPath(filePath); resPacker.SetHandlerParam(packHandlerParam); return(resPacker); }
//第一步 static public bool Build(string path, List <string> filePaths, EPackHandlerParam packHandlerParam, bool customPath = false, List <string> assetNames = null, List <UnityEngine.Object> assetList = null) { List <IResPacker> packers = new List <IResPacker>(); for (int i = 0; i < filePaths.Count; i++) { IResPacker resPacker = CreateResPacker(filePaths[i], packHandlerParam); packers.Add(resPacker); } return(Build(path, packers, packHandlerParam, customPath, assetNames, assetList)); }
/// 生成打包参数 EPackHandlerParam GeneratePackParam(BundlePackInfo ResInfo) { EPackHandlerParam packHandlerParam = EPackHandlerParam.None; if (ResInfo.HasFlag(EBundleFlag.UnCompress)) { packHandlerParam |= EPackHandlerParam.UnCompress; } if (ResInfo.HasFlag(EBundleFlag.LZMA)) { packHandlerParam |= EPackHandlerParam.LZMA; } if (ResInfo.HasFlag(EBundleFlag.LZ4)) { packHandlerParam |= EPackHandlerParam.LZ4; } return(packHandlerParam); }
/// 打包AssetBundle资源, void BuildBundleResource(BundlePackInfo packInfo, string ifsBuildDir, BuildTarget target) { if (packInfo == null) { return; } // 本次打包的路径和目录 string buildBundlePath = JW.Res.FileUtil.CombinePaths(ifsBuildDir, "", packInfo.Path); string buildBundleDirectory = JW.Res.FileUtil.GetFullDirectory(buildBundlePath); if (!JW.Res.FileUtil.IsDirectoryExist(buildBundleDirectory)) { JW.Res.FileUtil.CreateDirectory(buildBundleDirectory); } //========== build ========== List <string> filePathList = new List <string>(); List <string> nameList = new List <string>(); for (int j = 0; j < packInfo.Resources.Count; j++) { ResInfo res = packInfo.Resources[j]; filePathList.Add(res.RelativePath); nameList.Add(res.Path); } bool succ = false; //场景文件 if (packInfo.HasFlag(EBundleFlag.UnityScene)) { succ = ResPackHelper.BuildScene(filePathList, buildBundlePath); } else { //全局模式只是纯粹设置bundle 名称 if (_packConfig.IsGlobalBuild) { succ = ResPackHelper.JustSetBundleName(packInfo.Path, filePathList); } else { EPackHandlerParam packHandlerParam = GeneratePackParam(packInfo); succ = ResPackHelper.Build(buildBundlePath, filePathList, packHandlerParam, true, nameList); } } if (succ) { if (_packConfig.IsGlobalBuild) { JW.Common.Log.LogD("Set BundleName Success " + buildBundlePath); } else { JW.Common.Log.LogD("Build Bundle Success Out" + buildBundlePath); } } else { if (_packConfig.IsGlobalBuild) { Terminate("Set bundleName failed, path:" + buildBundlePath); } else { Terminate("Build bundle failed, path:" + buildBundlePath); } } }
public void SetHandlerParam(EPackHandlerParam packHandlerParam) { _mPackHandlerParam = packHandlerParam; }
//第2步 static bool Build(string path, List <IResPacker> packers, EPackHandlerParam packHandlerParam, bool customPath = false, List <string> assetNames = null, List <UnityEngine.Object> assetList = null) { IResPacker packer = null; Console.WriteLine("ResPackHelper Build " + path); //目前无预处理 if ((packHandlerParam & EPackHandlerParam.Preprocess) != 0) { for (int i = 0; i < packers.Count; i++) { packer = packers[i]; packer.Preprocess(); } Console.WriteLine("ResPackHelper Build Preprocess Finish " + path); } // 主预制件对象 if (null == assetList) { assetList = new List <UnityEngine.Object>(); } if (null == assetNames) { assetNames = new List <string>(); } for (int i = 0; i < packers.Count; i++) { packer = packers[i]; if (assetList.Count < packers.Count) { assetList.Add(packer.GetAimAssetObj()); } if (assetNames.Count < packers.Count) { assetNames.Add(GetFileFullPathWithoutExtension(packer.GetPath().Substring(7))); } } if (assetList.Count == 0) { for (int i = 0; i < packers.Count; i++) { packer = packers[i]; packer.Clear(); } return(false); } // BuildAssetBundleOptions buildOpts = BuildAssetBundleOptions.DeterministicAssetBundle; if (0 != (packHandlerParam & EPackHandlerParam.UnCompress)) { buildOpts |= BuildAssetBundleOptions.UncompressedAssetBundle; } else if (0 != (packHandlerParam & EPackHandlerParam.LZ4)) { buildOpts |= BuildAssetBundleOptions.ChunkBasedCompression; } else if (0 != (packHandlerParam & EPackHandlerParam.LZMA)) { //默认就是 } //优化 buildOpts |= BuildAssetBundleOptions.DisableWriteTypeTree; // build other bool bSucess = BuildAssetBundle(assetList.ToArray(), assetNames.ToArray(), path, buildOpts, customPath); // clear tmp asset for (int i = 0; i < packers.Count; i++) { packer = packers[i]; packer.Clear(); } return(bSucess); }