Dictionary <string, RD> FetchAllResources <RD, R>(string[] fileTypes) where RD : ResourceDetail where R : Resource { isSearching = true; Dictionary <string, RD> allDict = new Dictionary <string, RD>(); FileInfo[] resFiles = EditorFileUitl.GetAllFiles(Res_Root_Path, "*.*"); for (int i = 0; i < resFiles.Length; i++) { FileInfo fileInfo = resFiles[i]; string lowerName = fileInfo.Name.ToLower(); bool find = false; for (int j = 0; j < fileTypes.Length; j++) { if (lowerName.EndsWith(fileTypes[j])) { find = true; break; } } if (find) { string dir = EditorFileUitl.Absolute2Relativity(fileInfo.DirectoryName) + "/"; string path = dir + fileInfo.Name; EditorUtility.DisplayProgressBar("Resource Searching...", path, (float)i + 1.0f / (float)resFiles.Length); string md5 = ResUtils.GetFileMD5(path); RD rd = null; if (!allDict.TryGetValue(md5, out rd)) { rd = (RD)System.Activator.CreateInstance(typeof(RD), md5, fileInfo.Name); allDict.Add(md5, rd); } R r = (R)System.Activator.CreateInstance(typeof(R)); r.name = fileInfo.Name; r.path = dir + fileInfo.Name; r.SetResObj(AssetDatabase.LoadAssetAtPath <Object>(path)); r.fileInfo = fileInfo; r.hashCode = r.resObj.GetHashCode(); rd.resources.Add(r); } } EditorUtility.ClearProgressBar(); isSearching = false; return(allDict); }
/// <summary> /// 获取相同的文件 /// </summary> /// <param name="_PathValue"></param> /// <param name="assetsPaths"></param> /// <returns></returns> public static string[] GetSameFilePaths(string _PathValue, List <string> assetsPaths) { List <string> samePaths = new List <string>(); string _AssetMD5 = ResUtils.GetFileMD5(_PathValue); //遍历所有Assets for (int i = 0; i < assetsPaths.Count; i++) { if (assetsPaths[i] == _PathValue) { continue; } if (_AssetMD5 == ResUtils.GetFileMD5(assetsPaths[i])) { samePaths.Add(assetsPaths[i]); } } return(samePaths.ToArray()); }