/// <summary> /// 遍历文件 /// </summary> /// <param name="path"></param> /// <param name="dirPaths"></param> /// <param name="abNames"></param> /// <param name="resPaths"></param> /// <param name="ai"></param> public static void ListFiles(string path, List <string> dirPaths, List <string> abNames, Dictionary <string, ResPathInfo> resPaths, Dictionary <string, AssetBundleInfo> dependences, AssetImporter ai = null) { if (path.Contains(".meta")) { return; } if (AssetBuilder.IsIgnore(path)) { return; } string assetPath = EditorUtil.GetAssetsPath(path); if (ai == null) { ai = AssetImporter.GetAtPath(assetPath); } if (ai == null) { return; } string fileName = Path.GetFileNameWithoutExtension(path); string extension = Path.GetExtension(path); if (IsMarked(ai)) { if (abNames.IndexOf(ai.assetBundleName) == -1) { abNames.Add(ai.assetBundleName); } AddDependences(dependences, ai); } if (resPaths.ContainsKey(fileName)) { var info = resPaths[fileName]; string oldPath = string.Format("{0}/{1}{2}", dirPaths[info.resPathIndex], info.resName, info.extension); Debug.LogErrorFormat("资源名重复:{0}===>{1}", path, oldPath); } else { resPaths.Add(fileName, new ResPathInfo(fileName, extension, dirPaths.Count - 1, abNames.Count - 1)); } }
/// <summary> /// 遍历目录 /// </summary> /// <param name="path"></param> /// <param name="dirPaths"></param> /// <param name="abNames"></param> /// <param name="resPaths"></param> /// <param name="ai"></param> public static void ListDirectories(string path, List <string> dirPaths, List <string> abNames, Dictionary <string, ResPathInfo> resPaths, Dictionary <string, AssetBundleInfo> dependences, AssetImporter ai = null) { if (AssetBuilder.IsIgnore(path)) { return; } string assetPath = EditorUtil.GetAssetsPath(path); List <string> files = EditorUtil.GetFiles(path, "*", SearchOption.TopDirectoryOnly); if (files.Count > 0 && dirPaths.IndexOf(assetPath) == -1) { dirPaths.Add(assetPath); } if (ai == null) { ai = AssetImporter.GetAtPath(assetPath); } if (IsMarked(ai)) { if (abNames.IndexOf(ai.assetBundleName) == -1) { abNames.Add(ai.assetBundleName); } AddDependences(dependences, ai); } else { ai = null; } for (int i = 0; i < files.Count; i++) { ListFiles(files[i], dirPaths, abNames, resPaths, dependences, ai); } List <string> directories = EditorUtil.GetDirectories(path, "*", SearchOption.TopDirectoryOnly); for (int i = 0; i < directories.Count; i++) { ListDirectories(directories[i], dirPaths, abNames, resPaths, dependences, ai); } }