/// <summary> /// 生成BuildInfo信息 /// </summary> public bool GenBuildInfo() { //初始化数据 this.AssetTypeList = new List <string>(); this.BuildAssetsInfo = new BuildAssetsInfo(); this.RuntimeAssetsList = GetRuntimeAssetsInfo(); // var sw = new Stopwatch(); sw.Start(); BuildAssetsInfo.Time = DateTime.Now.ToShortDateString(); int id = 0; //搜集所有的依赖 foreach (var mainAsset in this.RuntimeAssetsList) { //这里会包含主资源 var dependAssetPathList = GetDependAssetList(mainAsset.importFrom); //获取依赖信息 并加入buildinfo foreach (var dependPath in dependAssetPathList) { //防止重复 if (BuildAssetsInfo.AssetDataMaps.ContainsKey(dependPath)) { continue; } //判断资源类型 var type = AssetBundleEditorToolsV2.GetMainAssetTypeAtPath(dependPath); if (type == null) { Debug.LogError("获取资源类型失败:" + dependPath); continue; } //构建资源类型 var assetData = new BuildAssetsInfo.BuildAssetData(); assetData.Id = id; assetData.Hash = this.GetHashFromAssets(dependPath); assetData.ABName = dependPath; var idx = AssetTypeList.FindIndex((a) => a == type.FullName); if (idx == -1) { AssetTypeList.Add(type.FullName); idx = AssetTypeList.Count - 1; } assetData.Type = idx; //获取依赖 var dependeAssetList = this.GetDependAssetList(dependPath); assetData.DependAssetList.AddRange(dependeAssetList); //添加 BuildAssetsInfo.AssetDataMaps[dependPath] = assetData; id++; } } //TODO AB依赖关系纠正 /// 已知Unity,bug/设计缺陷: /// 1.依赖接口,中会携带自己 /// 2.如若a.png、b.png 依赖 c.atlas,则abc依赖都会是:a.png 、b.png 、 a.atlas foreach (var asset in BuildAssetsInfo.AssetDataMaps) { //依赖中不包含自己 asset.Value.DependAssetList.Remove(asset.Value.ABName); } //获取依赖 this.DependAssetList = this.GetDependAssetsinfo(); //---------------------------------------end--------------------------------------------------------- //检查 foreach (var ar in this.RuntimeAssetsList) { if (!BuildAssetsInfo.AssetDataMaps.ContainsKey(ar.importFrom)) { Debug.LogError("AssetDataMaps遗漏资源:" + ar.importFrom); } } Debug.LogFormat("【GenBuildInfo】耗时:{0}ms.", sw.ElapsedMilliseconds); //检测构造的数据 var count = this.RuntimeAssetsList.Count + this.DependAssetList.Count; if (BuildAssetsInfo.AssetDataMaps.Count != count) { Debug.LogErrorFormat("【初始化框架资源环境】出错! buildinfo:{0} output:{1}", BuildAssetsInfo.AssetDataMaps.Count, count); var tmpBuildAssetsInfo = BuildAssetsInfo.Clone(); foreach (var ra in this.RuntimeAssetsList) { tmpBuildAssetsInfo.AssetDataMaps.Remove(ra.importFrom); } foreach (var drf in this.DependAssetList) { tmpBuildAssetsInfo.AssetDataMaps.Remove(drf.importFrom); } Debug.Log(JsonMapper.ToJson(tmpBuildAssetsInfo.AssetDataMaps, true)); return(false); } return(true); }