private static long ThreadFind(ThreadPars par) { long ret = 0; if (par != null) { for (int i = 0; i < par.ChildDataList.Count; i++) { ret += LoadFilesByThread(par.ChildDataList[i], par.DataPathList[i], 1); } } return(ret); }
private static Dictionary <string, List <string> > ThreadFind(ThreadPars par) { if (par != null) { Dictionary <string, List <string> > groupDi = new Dictionary <string, List <string> >(); for (int i = 0; i < par.ChildDataList.Count; i++) { AddressableDispatcher.Run(par.ChildDataList[i], par.is_atlas_model, groupDi); } return(groupDi); } return(null); }
private static List <string> ThreadFind(ThreadPars par) { if (par == null) { return(null); } List <string> ret = new List <string>(); for (int i = 0; i < par.imagePaths.Count; i++) { bool isHas = false; //查找资源是否有引用 string guid = par.imageGUIDPaths[i]; foreach (var fileContent in par.assetContents) { if (Regex.IsMatch(fileContent, guid)) { isHas = true; break; } } if (isHas) { continue; } //查找热更层代码 string matchStr = GetMatchImagePath(par.imagePaths[i]); foreach (var fileContent in par.codeContents) { if (Regex.IsMatch(fileContent, matchStr)) { isHas = true; break; } } if (!isHas) { ret.Add(par.imagePaths[i]); } } return(ret); }
private void StartCheck() { EditorSettings.serializationMode = SerializationMode.ForceText; AssetDatabase.Refresh(); List <string> imagePaths = UIAssetUtils.GetAllImages(false); imagePaths = imagePaths.Where(s => !Regex.IsMatch(s, "ColorPokerCard")).Where(s => !Regex.IsMatch(s, "PokerCard")).ToList(); List <string> withoutExtensions = new List <string>() { ".prefab", ".unity", ".mat", ".cs" }; string[] files = Directory.GetFiles(Path.Combine(Application.dataPath, "AssetsPackage"), "*.*", SearchOption.AllDirectories) .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray(); //预先load内容 List <string> assetContents = new List <string>(); foreach (var file in files) { assetContents.Add(File.ReadAllText(file)); } files = Directory.GetFiles("Codes", "*.*", SearchOption.AllDirectories) .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray(); List <string> codeContents = new List <string>(); foreach (var file in files) { codeContents.Add(File.ReadAllText(file)); } ThreadPars[] threadParses = new ThreadPars[ThreadCount]; for (int i = 0; i < ThreadCount; i++)//添加查找的范围内容 { threadParses[i] = new ThreadPars(); threadParses[i].assetContents = assetContents; threadParses[i].codeContents = codeContents; } for (int i = 0; i < imagePaths.Count; i++) { int index = i % ThreadCount; threadParses[index].imagePaths.Add(imagePaths[i]); threadParses[index].imageGUIDPaths.Add(AssetDatabase.AssetPathToGUID(imagePaths[i])); } ThreadRun[] tRun = new ThreadRun[ThreadCount]; int finishedState = ThreadCount; IAsyncResult[] results = new IAsyncResult[ThreadCount]; _updateDelegate = delegate { var finishedCount = 0; for (int i = 0; i < ThreadCount; i++) { if (results[i].IsCompleted) { ++finishedCount; } } EditorUtility.DisplayProgressBar("匹配资源中", string.Format("进度:{0}", finishedCount), (float)finishedCount / ThreadCount); if (finishedCount >= finishedState) { for (int i = 0; i < ThreadCount; i++) { List <string> temRunThreadData = tRun[i].EndInvoke(results[i]); foreach (var path in temRunThreadData) { Results.Add(path); } } EditorUtility.ClearProgressBar(); EditorApplication.update -= _updateDelegate; this.ShowNotification(new GUIContent("查找完成!")); isDone = true; watch.Stop(); UnityEngine.Debug.Log("累计用时:" + watch.ElapsedMilliseconds); } }; for (int i = 0; i < ThreadCount; i++) { tRun[i] = ThreadFind; results[i] = tRun[i].BeginInvoke(threadParses[i], null, null); } EditorApplication.update += _updateDelegate; }
private static long LoadFilesThread(Data data, string currentPath, int indent = 0) { GUIContent content = GetGUIContent(currentPath); long dataSize = 0; if (content != null) { data.indent = indent; data.content = content; data.assetPath = currentPath; data.isIllegalImage = ValidateImage(currentPath); data.fileMemorySize = MemorySize(currentPath); } foreach (var path in Directory.GetFiles(currentPath)) { content = GetGUIContent(path); if (content != null) { Data child = new Data(); child.indent = indent + 1; child.content = content; child.assetPath = path; child.isIllegalImage = ValidateImage(path); child.fileMemorySize = MemorySize(path); //FileInfo fi = new FileInfo(path); //child.fileSize = fi.Length; //dataSize += fi.Length; child.fileSize = FileSize(path); dataSize += child.fileSize; data.childs.Add(child); } } ThreadPars[] threadParses = new ThreadPars[ThreadCount]; for (int index = 0; index < ThreadCount; index++) { threadParses[index] = new ThreadPars(); } var i = 0; foreach (var path in Directory.GetDirectories(currentPath)) { Data childDir = new Data(); data.childs.Add(childDir); int index = i % ThreadCount; threadParses[index].ChildDataList.Add(childDir); threadParses[index].DataPathList.Add(path); i++; //dataSize += LoadFilesThread (childDir,path, indent + 1); } ThreadRun[] tRun = new ThreadRun[ThreadCount]; int finishedState = ThreadCount; IAsyncResult[] results = new IAsyncResult[ThreadCount]; _updateDelegate = delegate { var finishedCount = 0; for (int j = 0; j < ThreadCount; j++) { if (results[j].IsCompleted) { ++finishedCount; } } EditorUtility.DisplayProgressBar("匹配资源中", string.Format("进度:{0}", finishedCount), (float)finishedCount / ThreadCount); if (finishedCount >= finishedState) { for (int j = 0; j < ThreadCount; j++) { dataSize += tRun[j].EndInvoke(results[j]); } EditorUtility.ClearProgressBar(); EditorApplication.update -= _updateDelegate; ArtToolsWindow window = (ArtToolsWindow)EditorWindow.GetWindow(typeof(ArtToolsWindow)); window.Show(); data.fileSize = dataSize; //LogData(); } }; for (int j = 0; j < ThreadCount; j++) { tRun[j] = ThreadFind; results[j] = tRun[j].BeginInvoke(threadParses[j], null, null); } EditorApplication.update += _updateDelegate; data.fileSize = dataSize; return(dataSize); }
private static Dictionary <string, List <string> > ThreadFind(ThreadPars par) { Dictionary <string, List <string> > ret = new Dictionary <string, List <string> >(); if (par != null) { foreach (var file in par.CheckAssetList) { string fileContent = File.ReadAllText(file); foreach (var aimGuid in par.AssetGuidList) { if (Regex.IsMatch(fileContent, aimGuid)) { if (ret.ContainsKey(aimGuid)) { ret[aimGuid].Add(file); } else { List <string> list = new List <string>(); list.Add(file); ret.Add(aimGuid, list); } } } } foreach (var file in par.CheckCSList) { string fileContent = File.ReadAllText(file); foreach (var aimName in par.AssetNameList) { var checkName = Path.GetFileName(aimName); if (Regex.IsMatch(fileContent, checkName)) { if (ret.ContainsKey(aimName)) { ret[aimName].Add(file); } else { List <string> list = new List <string>(); list.Add(file); ret.Add(aimName, list); } } } } foreach (var file in par.CheckWihteList) { string fileContent = file; foreach (var aimName in par.AssetNameList) { var checkName = Path.GetFileName(aimName); if (Regex.IsMatch(checkName, fileContent)) { if (ret.ContainsKey(aimName)) { ret[aimName].Add(file); } else { List <string> list = new List <string>(); list.Add(file); ret.Add(aimName, list); } } } } } return(ret); }
//[MenuItem("Assets/Find References Thread",false,10)] public static void FindThread(string path, bool outExcel = false) { refDic.Clear(); EditorSettings.serializationMode = SerializationMode.ForceText; AssetDatabase.Refresh(); //string path = AssetDatabase.GetAssetPath(Selection.activeObject); if (!string.IsNullOrEmpty(path)) { List <string> _AssetGuidList = new List <string>(); List <string> _AssetNameList = new List <string>(); if (Directory.Exists(path)) { string[] assetPathsFromFolder = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories); foreach (var tempPath in assetPathsFromFolder) { if (!tempPath.EndsWith(".meta")) { var assetFindPath = GetRelativeAssetsPath(tempPath); _AssetNameList.Add(assetFindPath); _AssetGuidList.Add(AssetDatabase.AssetPathToGUID(assetFindPath)); } } } else { _AssetGuidList.Add(AssetDatabase.AssetPathToGUID(path)); _AssetNameList.Add(path); } ThreadPars[] threadParses = new ThreadPars[ThreadCount]; for (int i = 0; i < ThreadCount; i++)//添加查找的udid { threadParses[i] = new ThreadPars(); threadParses[i].AssetGuidList = _AssetGuidList; threadParses[i].AssetNameList = _AssetNameList; } List <string> withoutExtensions = new List <string>() { ".prefab", ".unity", ".mat", ".asset" }; string[] files = Directory.GetFiles(Path.Combine(Application.dataPath, "AssetsPackage"), "*.*", SearchOption.AllDirectories) .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray(); for (int i = 0; i < files.Length; i++)//添加要查找的资源文件 { int index = i % ThreadCount; threadParses[index].CheckAssetList.Add(files[i]); } string[] csFiles = Directory.GetFiles(Application.dataPath, "*.cs", SearchOption.AllDirectories) .Where(s => s.IndexOf("/editor/", System.StringComparison.OrdinalIgnoreCase) < 0).ToArray(); for (int i = 0; i < csFiles.Length; i++)//添加要查找的CS文件 { int index = i % ThreadCount; threadParses[index].CheckCSList.Add(csFiles[i]); } ThreadRun[] tRun = new ThreadRun[ThreadCount]; int finishedState = ThreadCount; IAsyncResult[] results = new IAsyncResult[ThreadCount]; _updateDelegate = delegate { var finishedCount = 0; for (int i = 0; i < ThreadCount; i++) { if (results[i].IsCompleted) { ++finishedCount; } } EditorUtility.DisplayProgressBar("匹配资源中", string.Format("进度:{0}", finishedCount), (float)finishedCount / ThreadCount); if (finishedCount >= finishedState) { for (int i = 0; i < ThreadCount; i++) { Dictionary <string, List <string> > temRunThreadData = tRun[i].EndInvoke(results[i]); foreach (var keyValue in temRunThreadData) { var key = keyValue.Key; if (key.Contains("/") || key.Contains("\\")) { key = AssetDatabase.AssetPathToGUID(key); } if (refDic.ContainsKey(key)) { refDic[key].AddRange(keyValue.Value); } else { refDic.Add(key, keyValue.Value); } } } EditorUtility.ClearProgressBar(); EditorApplication.update -= _updateDelegate; if (outExcel) { OutputToExcel(); } else { FindReferences01 window = (FindReferences01)EditorWindow.GetWindow(typeof(FindReferences01)); window.Show(); } } }; for (int i = 0; i < ThreadCount; i++) { tRun[i] = ThreadFind; results[i] = tRun[i].BeginInvoke(threadParses[i], null, null); } EditorApplication.update += _updateDelegate; } }
private static void RunAllCheckersTask() { ThreadPars[] threadParses = new ThreadPars[ThreadCount]; for (int index = 0; index < ThreadCount; index++) { threadParses[index] = new ThreadPars(); } var guids = AssetDatabase.FindAssets("t:AddressableDispatcherConfig", new string[] { AddressableInspectorUtils.DatabaseRoot }); var length = guids.Length; var count = 0; foreach (var guid in guids) { count++; var assetPath = AssetDatabase.GUIDToAssetPath(guid); var config = AssetDatabase.LoadAssetAtPath <AddressableDispatcherConfig>(assetPath); config.Load(); int index = count % ThreadCount; threadParses[index].ChildDataList.Add(config); threadParses[index].is_atlas_model = EditorUserSettings.GetConfigValue(AddressableTools.is_atlas_model); } List <Task <Dictionary <string, List <string> > > > taskList = new List <Task <Dictionary <string, List <string> > > >(); taskList.Add(new Task <Dictionary <string, List <string> > >(() => { return(ThreadFind(threadParses[0])); })); taskList[0].Start(); taskList.Add(new Task <Dictionary <string, List <string> > >(() => { return(ThreadFind(threadParses[1])); })); taskList[1].Start(); taskList.Add(new Task <Dictionary <string, List <string> > >(() => { return(ThreadFind(threadParses[2])); })); taskList[2].Start(); taskList.Add(new Task <Dictionary <string, List <string> > >(() => { return(ThreadFind(threadParses[3])); })); taskList[3].Start(); for (int i = 0; i < ThreadCount; i++) { taskList[i].Wait(); } //Logger.LogError("=======over========="); Dictionary <string, UnityEditor.AddressableAssets.Settings.AddressableAssetGroup> groupsDic = new Dictionary <string, UnityEditor.AddressableAssets.Settings.AddressableAssetGroup>(); for (int i = 0; i < ThreadCount; i++) { foreach (var keyvalue in taskList[i].Result) { keyvalue.Value.Sort(); foreach (var pathStr in keyvalue.Value) { //Logger.LogError("path:" + pathStr + " groupName:" + keyvalue.Key); if (!groupsDic.ContainsKey(keyvalue.Key)) { groupsDic.Add(keyvalue.Key, AASUtility.CreateGroup(keyvalue.Key)); } UnityEditor.AddressableAssets.Settings.AddressableAssetEntry temp_entry = null; var s = AASUtility.GetSettings(); foreach (UnityEditor.AddressableAssets.Settings.AddressableAssetGroup group in s.groups) { if (group == null) { continue; } foreach (UnityEditor.AddressableAssets.Settings.AddressableAssetEntry entry in group.entries) { //Logger.LogError("entry.AssetPath:" + entry.AssetPath + " pathstr:" + pathStr + " group.name:" + group.name + " keyvalue.key:" + keyvalue.Key); if ((entry.AssetPath.Replace('\\', '/') == pathStr.Replace('\\', '/')) && (group.name == keyvalue.Key)) { //Logger.LogError("============temp_entry=====================" + pathStr); temp_entry = entry; } } } if (temp_entry == null) { //Logger.LogError("=================================" + pathStr); var guid = AssetDatabase.AssetPathToGUID(pathStr); AASUtility.AddAssetToGroup(guid, keyvalue.Key); } } } } AssetDatabase.Refresh(); }