/// <summary> /// 创建构建资产信息 /// </summary> /// <param name="assetPath"></param> /// <returns></returns> public BuildingAssetInfos.AssetInfo CreateAssetInfo(string assetPath) { //判断资源类型 var type = AssetBundleEditorToolsV2.GetMainAssetTypeAtPath(assetPath); if (type == null) { Debug.LogError("获取资源类型失败:" + assetPath); return(null); } //创建 var assetInfo = new BuildingAssetInfos.AssetInfo(); assetInfo.Hash = this.GetHashFromAssets(assetPath); assetInfo.ABName = assetPath; var idx = this.AssetTypeList.FindIndex((a) => a == type.FullName); if (idx == -1) { this.AssetTypeList.Add(type.FullName); idx = AssetTypeList.Count - 1; } assetInfo.Type = idx; //依赖列表 var dependeAssetList = this.GetDependAssetList(assetPath); assetInfo.DependAssetList = new List <string>(dependeAssetList); return(assetInfo); }
/// <summary> /// 获取BuildAssetsInfo /// </summary> /// <returns></returns> private BuildingAssetInfos GetBuildingAssetInfos(BuildingAssetInfos buildingInfoCache = null) { var retBuildingInfo = new BuildingAssetInfos(); //开始 var sw = new Stopwatch(); sw.Start(); retBuildingInfo.Time = DateTime.Now.ToShortDateString(); int id = 0; //1.获取runtime资产 runtimeAssetsPathList = GetRuntimeAssetsPath(); //2.搜集所有的依赖资产 var allAssetList = new List <string>(); allAssetList.AddRange(runtimeAssetsPathList); //获取所有依赖 for (int i = 0; i < runtimeAssetsPathList.Count; i++) { var runtimeAsset = runtimeAssetsPathList[i]; BuildingAssetInfos.AssetInfo assetInfo = null; //从缓存取依赖 buildingInfoCache?.AssetInfoMap.TryGetValue(runtimeAsset, out assetInfo); if (assetInfo != null) { allAssetList.AddRange(assetInfo.DependAssetList); } else { var dependList = this.GetDependAssetList(runtimeAsset); allAssetList.AddRange(dependList); } } //去重 allAssetList = allAssetList.Distinct().ToList(); //用所有资源构建AssetMap foreach (var assetPath in allAssetList) { //防止重复 if (retBuildingInfo.AssetInfoMap.ContainsKey(assetPath)) { continue; } //优先从缓存获取 var assetInfo = buildingInfoCache?.GetNewInstanceAssetInfo(assetPath); if (assetInfo == null) { //构建资源信息 assetInfo = CreateAssetInfo(assetPath); } //添加 assetInfo.Id = retBuildingInfo.AssetInfoMap.Count + 1; retBuildingInfo.AssetInfoMap[assetPath] = assetInfo; } //TODO AB依赖关系纠正 /// 已知Unity,bug/设计缺陷: /// 1.依赖接口,中会携带自己 /// 2.如若a.png、b.png 依赖 c.atlas,则abc依赖都会是:a.png 、b.png 、 a.atlas // foreach (var asset in buildingAssetInfos.AssetDataMaps) // { // //依赖中不包含自己 // //asset.Value.DependAssetList.Remove(asset.Key); // } sw.Stop(); Debug.LogFormat("【GenBuildInfo】耗时:{0}ms.", sw.ElapsedMilliseconds); return(retBuildingInfo); }