/// <summary> /// 每次打包assetsbundle的前要获取整个配置文件 /// </summary> static void GetConfig() { config = null; var bytes = FileTools.TryReadFile(ConfigFile); config = (bytes == null) ? new AssetsBundleConfig() : JsonMapper.ToObject <AssetsBundleConfig>(Encoding.UTF8.GetString(bytes)); }
//从本地配置生成路径字典 private static void InitPathDic() { AssetsBundleConfig config = AssetDatabase.LoadAssetAtPath <AssetsBundleConfig>(AB_CONFIG_PATH); //获取已文件夹为单位打包的字典 foreach (var info in config.FolderPathList) { if (FolderPathDic.ContainsKey(info.Name) == false) { FolderPathDic.Add(info.Name, info.Path); FilterPathList.Add(info.Path); VaildPathList.Add(info.Path); } else { Debug.LogError("配置错误,包名重复"); } } //获取以单个Prefab为单位打包的路径字典 string[] allPath = AssetDatabase.FindAssets("t:Prefab", config.SinglePathList.ToArray()); for (int i = 0; i < allPath.Length; ++i) { string path = AssetDatabase.GUIDToAssetPath(allPath[i]); EditorUtility.DisplayProgressBar("查找Prefab", path, i * 1.0f / allPath.Length); VaildPathList.Add(path); if (PathExist(path) == false) { GameObject go = AssetDatabase.LoadAssetAtPath <GameObject>(path); string[] allDepend = AssetDatabase.GetDependencies(path); List <string> allDependPath = new List <string>(); for (int j = 0; j < allDepend.Length; ++j) { //过滤掉已存在的路径和C#脚本 if (PathExist(allDepend[j]) == false && allDepend[j].EndsWith(".cs") == false) { FilterPathList.Add(allDepend[j]); allDependPath.Add(allDepend[j]); } } if (PrefabDependDic.ContainsKey(go.name) == false) { PrefabDependDic.Add(go.name, allDependPath); } else { Debug.LogError("存在相同名字的Prefab:" + go.name); } } } }