/// <summary> ///TODO : 待实现 /// 获取改动的Assets /// </summary> static BuildInfo GetChangedAssets(BuildInfo lastInfo, BuildInfo newInfo) { var list = new List <BuildInfo.AssetData>(); //比较 assetdata foreach (var item in newInfo.AssetDataMaps) { BuildInfo.AssetData lastAsset = null; //同名文件 hash不一样 if (lastInfo.AssetDataMaps.TryGetValue(item.Key, out lastAsset)) { if (lastAsset.Hash != item.Value.Hash) { list.Add(item.Value); } } else { list.Add(item.Value); } } //根据变动的list 刷出关联 //1.单ab 单资源,直接重打 //2.单ab 多资源的 整个ab都要重新打包 if (lastInfo.AssetDataMaps.Count != 0) { } return(newInfo); }
/// <summary> /// 获取改动的Assets /// </summary> static BuildInfo GetChangedAssets(BuildInfo lastAssetsInfo, BuildInfo newAssetsInfo) { //根据变动的list 刷出关联 //1.单ab 单资源,直接重打 //2.单ab 多资源的 整个ab都要重新打包 if (lastAssetsInfo.AssetDataMaps.Count != 0) { Debug.Log("<color=red>开始增量分析...</color>"); var changedAssetList = new List <KeyValuePair <string, BuildInfo.AssetData> >(); //找出差异文件 foreach (var newAssetItem in newAssetsInfo.AssetDataMaps) { BuildInfo.AssetData lastAssetData = null; if (lastAssetsInfo.AssetDataMaps.TryGetValue(newAssetItem.Key, out lastAssetData)) { if (lastAssetData.Hash == newAssetItem.Value.Hash) { continue; } } changedAssetList.Add(newAssetItem); } Debug.LogFormat("<color=red>变动文件数:{0}</color>", changedAssetList.Count); //rebuild List <string> rebuildABNameList = new List <string>(); foreach (var tempAsset in changedAssetList) { //1.添加自身的ab rebuildABNameList.Add(tempAsset.Value.ABName); //2.添加所有依赖的ab foreach (var depend in tempAsset.Value.DependList) { BuildInfo.AssetData dependAssetData = null; if (newAssetsInfo.AssetDataMaps.TryGetValue(depend, out dependAssetData)) { rebuildABNameList.Add(dependAssetData.ABName); } else { Debug.LogError("不存在资源:" + depend); } } } //去重 rebuildABNameList = rebuildABNameList.Distinct().ToList(); //搜索依赖的ab,直到没有新ab为止 int counter = 0; while (counter < rebuildABNameList.Count) //防死循环 { string abName = rebuildABNameList[counter]; var findAssets = newAssetsInfo.AssetDataMaps.Where((asset) => asset.Value.ABName == abName); foreach (var asset in findAssets) { //添加本体 var assetdata = newAssetsInfo.AssetDataMaps[asset.Key]; if (!rebuildABNameList.Contains(assetdata.ABName)) { rebuildABNameList.Add(assetdata.ABName); } //添加依赖文件 foreach (var depend in assetdata.DependList) { BuildInfo.AssetData dependAssetData = null; if (newAssetsInfo.AssetDataMaps.TryGetValue(depend, out dependAssetData)) { if (!rebuildABNameList.Contains(dependAssetData.ABName)) { rebuildABNameList.Add(dependAssetData.ABName); } } else { Debug.LogError("不存在资源:" + depend); } } } counter++; } var allRebuildAssets = new List <KeyValuePair <string, BuildInfo.AssetData> >(); //根据影响的ab,寻找出所有文件 foreach (var abname in rebuildABNameList) { var findAssets = newAssetsInfo.AssetDataMaps.Where((asset) => asset.Value.ABName == abname); allRebuildAssets.AddRange(findAssets); } //去重 var retBuildInfo = new BuildInfo(); foreach (var kv in allRebuildAssets) { retBuildInfo.AssetDataMaps[kv.Key] = kv.Value; } Debug.LogFormat("<color=red>影响文件数:{0}</color>", retBuildInfo.AssetDataMaps.Count); return(retBuildInfo); } return(newAssetsInfo); }
/// <summary> /// 获取当前所有资源配置 /// </summary> /// <returns></returns> static public BuildInfo GetAssetsInfo(List <string> paths) { packageAssetsMap = new Dictionary <string, List <string> >(); //1.获取图集信息 var atlas = paths.FindAll((p) => Path.GetExtension(p) == ".spriteatlas"); for (int i = 0; i < atlas.Count; i++) { var asset = atlas[i]; //获取依赖中的textrue var dps = GetDependencies(asset).ToList(); packageAssetsMap[asset] = dps; } //2.搜集Package config信息 foreach (var config in PackageConfigMap) { var rets = paths.FindAll((p) => config.FileExtens.Contains(Path.GetExtension(p))); packageAssetsMap[config.AssetBundleName] = rets.ToList(); } // BuildInfo buildInfo = new BuildInfo(); buildInfo.Time = DateTime.Now.ToShortDateString(); int id = 0; //搜集所有的依赖 foreach (var mainpath in paths) { var dependeAssetsPath = GetDependencies(mainpath); //获取依赖 并加入build info foreach (var subAssetPath in dependeAssetsPath) { var asset = new BuildInfo.AssetData(); asset.Id = id; asset.Hash = GetHashFromAssets(subAssetPath); asset.ABName = subAssetPath; //判断资源类型 asset.Type = (int)ManifestItem.AssetTypeEnum.Others; var subAssetsExtension = Path.GetExtension(subAssetPath); // foreach (var item in AssetTypeConfigMap) { if (item.Value.Contains(subAssetsExtension)) { asset.Type = (int)item.Key; break; } } //获取依赖 var dependeAssetList = GetDependencies(subAssetPath); asset.DependList.AddRange(dependeAssetList); //添加 buildInfo.AssetDataMaps[subAssetPath] = asset; //判断package名 //图集 foreach (var item in packageAssetsMap) { if (item.Value.Contains(subAssetPath)) { //设置AB的名字 asset.ABName = item.Key; break; } } //自己规则的ab foreach (var item in PackageConfigMap) { if (item.FileExtens.Contains(subAssetsExtension)) { //设置AB的名字 asset.ABName = item.AssetBundleName; break; } } id++; } } //TODO AB依赖关系纠正 /// 已知Unity,bug/设计缺陷: /// 1.依赖接口,中会携带自己 /// 2.如若a.png、b.png 依赖 c.atlas,则abc依赖都会是:a.png 、b.png 、 a.atlas foreach (var asset in buildInfo.AssetDataMaps) { //依赖中不包含自己 asset.Value.DependList.Remove(asset.Value.ABName); } //2.Package Config信息添加到BuildInfo foreach (var config in PackageConfigMap) { var asset = new BuildInfo.AssetData(); asset.ABName = config.AssetBundleName; //添加依赖 var rets = buildInfo.AssetDataMaps.Values.Where((a) => a.ABName == config.AssetBundleName); asset.DependList.AddRange(rets.Select((r) => r.ABName)); //压入列表 buildInfo.AssetDataMaps[asset.ABName] = asset; } //搜集引用的次数,以runtime内部引用为主 foreach (var item in buildInfo.AssetDataMaps) { if (!item.Key.Contains("/runtime/")) { continue; } // int count = 0; foreach (var assetdata in buildInfo.AssetDataMaps.Values) { if (assetdata.DependList.Contains(item.Key)) { count++; } } item.Value.ReferenceCount = count; } return(buildInfo); }
/// <summary> /// 获取当前所有资源配置 /// </summary> /// <returns></returns> static public BuildInfo GetAssetsInfo(List <string> paths) { atlasAssetsMap = new Dictionary <string, List <string> >(); //1.获取图集信息 var atlas = paths.FindAll((p) => Path.GetExtension(p) == ".spriteatlas"); for (int i = 0; i < atlas.Count; i++) { var asset = atlas[i]; //获取依赖中的textrue var dps = GetDependencies(asset).ToList(); atlasAssetsMap[asset] = dps; } //2.搜集Package config信息 foreach (var config in PackageConfigMap) { var rets = paths.FindAll((p) => config.FileExtens.Contains(Path.GetExtension(p))); atlasAssetsMap[config.AssetBundleName] = rets.ToList(); } // BuildInfo buildInfo = new BuildInfo(); buildInfo.Time = DateTime.Now.ToShortDateString(); int id = 0; //搜集所有的依赖 foreach (var mainpath in paths) { var dependeAssetsPath = GetDependencies(mainpath); //获取依赖 并加入build info foreach (var subAssetPath in dependeAssetsPath) { var asset = new BuildInfo.AssetData(); asset.Id = id; asset.Hash = GetHashFromAssets(subAssetPath); asset.Name = subAssetPath; //判断资源类型 asset.Type = (int)ManifestItem.AssetTypeEnum.Others; var subAssetsExtension = Path.GetExtension(subAssetPath); // foreach (var item in AssetTypeConfigMap) { if (item.Value.Contains(subAssetsExtension)) { asset.Type = (int)item.Key; break; } } //获取依赖 var dependeAssetList = GetDependencies(subAssetPath); asset.DependList.AddRange(dependeAssetList); //添加 buildInfo.AssetDataMaps[subAssetPath] = asset; //判断package名 //图集 foreach (var item in atlasAssetsMap) { if (item.Value.Contains(subAssetPath)) { //设置AB的名字 asset.AB = item.Key; break; } } //自己规则的ab foreach (var item in PackageConfigMap) { if (item.FileExtens.Contains(subAssetsExtension)) { //设置AB的名字 asset.AB = item.AssetBundleName; break; } } id++; } } //TODO AB依赖关系纠正 /// 已知Unity,bug/设计缺陷: /// 1.依赖接口,中会携带自己 /// 2.如若a.png、b.png 依赖 c.atlas,则abc依赖都会是:a.png 、b.png 、 a.atlas foreach (var asset in buildInfo.AssetDataMaps) { //依赖中不包含自己 asset.Value.DependList.Remove(asset.Value.Name); } //1.剔除图片会依赖图集的依赖, var atlasList = buildInfo.AssetDataMaps.Values.Where((a) => a.Type == (int)ManifestItem.AssetTypeEnum.SpriteAtlas); foreach (var _atlas in atlasList) { foreach (var img in _atlas.DependList) { if (img == _atlas.Name) { continue; } var imgAsset = buildInfo.AssetDataMaps[img]; imgAsset.DependList.Clear(); } } //2.把依赖资源替换成AB Name, foreach (var asset in buildInfo.AssetDataMaps.Values) { for (int i = 0; i < asset.DependList.Count; i++) { var da = asset.DependList[i]; var dependAssetData = buildInfo.AssetDataMaps[da]; //替换成真正AB名 if (!string.IsNullOrEmpty(dependAssetData.AB)) { asset.DependList[i] = dependAssetData.AB; } } //去重 asset.DependList = asset.DependList.Distinct().ToList(); } return(buildInfo); }