/// <summary> /// Release 资源剪裁 /// </summary> /// <param name="buildTarget"></param> /// <param name="bundleMapPath"></param> /// <returns></returns> private static bool StrippingResourcesForRelease(BuildTarget buildTarget, string bundleMapPath) { BundleIndicesMap fullBundleIndexMap = new BundleIndicesMap($"{PathConfig.CODE_STREAMINGASSET_PATH}/bundlemap.bytes"); List <BundleIndexItemInfo> allBundleInfoList = fullBundleIndexMap.GetAllBundleIndexItemList(); fullBundleIndexMap.Dispose(); Dictionary <string, BundleIndexItemInfo> allBundleDict = allBundleInfoList.ToDictionary(bundleIndexItem => bundleIndexItem.BundleName); List <string> allBundleKeyList = allBundleDict.Keys.ToList(); Dictionary <string, object> existStripSet = ReleaseStripping.GetStrippingAssets(); HashSet <string> appendSet = new HashSet <string>(); string strippintReportPath = GetStrippingReportPath(buildTarget); for (int i = 0; i < allBundleKeyList.Count; ++i) { string bundleName = allBundleKeyList[i]; if (existStripSet.ContainsKey(bundleName)) { existStripSet.Remove(bundleName); } else { appendSet.Add(bundleName); } } if (appendSet.Count == 0 && existStripSet.Count == 0) { Dictionary <string, object> strippingDict = ReleaseStripping.GetStrippingAssets(); string buildOutputPath = GetBuildBundleMapPath(buildTarget); BundleIndicesMap bundlemapDb = new BundleIndicesMap($"{buildOutputPath}/bundlemap.bytes"); Dictionary <string, BundleIndexItemInfo> allBundleMapDict = bundlemapDb.GetAllBundleIndexItemList().ToDictionary(item => item.BundleName); bundlemapDb.BundleIndicesMapConn.BeginTransaction(); foreach (var pair in strippingDict) { ReleaseStrippingForTheChief.AssetManifestConfig assetManifestConfig = (ReleaseStrippingForTheChief.AssetManifestConfig)pair.Value; if ((ReleaseStrippingForTheChief.AssetLevel)assetManifestConfig.AssetLevel != ReleaseStrippingForTheChief.AssetLevel.BUILDIN) { string strippingBundlePath = Path.Combine(buildOutputPath, allBundleMapDict[pair.Key].BundleHashName); File.Delete(strippingBundlePath); bundlemapDb.RemoveBundleIndices(pair.Key); } } bundlemapDb.Dispose(); File.Delete(strippintReportPath); return(true); } else { List <string> obsoluteBundleList = existStripSet.Keys.ToList(); List <string> appendBundleList = appendSet.ToList(); StrippingReport report = new StrippingReport(); report.ObsoluteAssets.AddRange(obsoluteBundleList); report.NotIncludeAssets.AddRange(appendBundleList); using (FileStream fs = new FileStream(strippintReportPath, FileMode.Create)) { byte[] writeBuffer = Encoding.Default.GetBytes(JsonMapper.ToJson(report)); fs.Write(writeBuffer, 0, writeBuffer.Length); } return(false); } }
public static void PackAllIOSx() { ReleaseStripping.GetStrippingAssets(); StrippingResourcesForRelease(BuildTarget.StandaloneWindows64, @"D:\workroot\conan\trunk\public\exp\exp_bundle\bundlemap.bytes"); }