/// <summary> /// 导出一个指定的包 /// </summary> /// <param name="info"></param> /// <returns></returns> static bool BuildPackage(PackageInfo info, BuildTarget buildTarget) { //打包package下的所有资源 UnityEngine.Object[] arrAssetObject = new UnityEngine.Object[info.packageAssets.Length]; string[] arrAssetNameInPackage = new string[info.packageAssets.Length]; for (int i = 0; i < info.packageAssets.Length; ++i) { string assetPath = info.packageAssets[i]; arrAssetObject[i] = AssetDatabase.LoadMainAssetAtPath(assetPath); arrAssetNameInPackage[i] = GetAssetNameInPackage(assetPath).ToLower();//包中物体的名字,目前是相对与package目录的完整路径,以后可以修改 CheckAssetValid(assetPath, arrAssetObject[i]); } //这里使用CollectDependencies,但是由于外层使用了PushDependcies,所以依赖项可能是在其他的包中 string strOutputPath = info.GetBundlePath(buildTarget);// BuilderTools.GetOutputPath(buildTarget) + info.packageName + BUNDLE_EXT; BuildPipeline.BuildAssetBundleExplicitAssetNames(arrAssetObject, arrAssetNameInPackage, strOutputPath , BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.DeterministicAssetBundle, buildTarget); //生成信息文件 string strPackageInfoFilePath = info.GetInfoPath(buildTarget);// BuilderTools.GetOutputPath(buildTarget) + info.packageName + PACKAGE_INFO_EXT; WritePackageInfoFile(strPackageInfoFilePath, info.ltDepPackages); //生成版本信息文件,依赖项的信息要做为md5的一部分 string strVersionFilePath = info.GetVersionPath(buildTarget); string strVersion = BuilderTools.GetVerifyString(new string[] { strPackageInfoFilePath }, new string[] { info.packagePath }); File.WriteAllText(strVersionFilePath, strVersion); //写入统一的dat文件 string strDataFilePath = info.GetDataPath(buildTarget);// BuilderTools.GetOutputPath(buildTarget) + info.packageName + DATA_EXT; CombineFinalPackage(strPackageInfoFilePath, strOutputPath, strDataFilePath); Debug.Log("writed output file: " + strDataFilePath); return true; }