public static HierarchyReferenceItem[] FindHierarchyObjectsReferences(Object[] allObjects, Object[] newObjects, bool showResults = true) { var results = new List <HierarchyReferenceItem>(); try { var sw = Stopwatch.StartNew(); CSEditorTools.lastRevealSceneOpenResult = null; EntryGenerator.ResetCachedObjects(); var searchCanceled = LookForObjectsReferencesInHierarchy(allObjects, results); sw.Stop(); EditorUtility.ClearProgressBar(); if (!searchCanceled) { var referencesFound = 0; foreach (var result in results) { if (result.depth == 1) { referencesFound++; } } if (referencesFound == 0) { HierarchyReferencesTab.AutoSelectHierarchyReference = null; MaintainerWindow.ShowNotification("Nothing found!"); } else { if (newObjects != null && newObjects.Length > 0) { var totalFoundFromNew = GetFoundObjects(newObjects, results); if (totalFoundFromNew.Count == 0) { HierarchyReferencesTab.AutoSelectHierarchyReference = null; MaintainerWindow.ShowNotification("Nothing found!"); } else { if (HierarchyReferencesTab.AutoSelectHierarchyReference == null) { if (totalFoundFromNew.Count == 1) { var firstFound = totalFoundFromNew[0]; var entry = ObjectToReferencingEntry(firstFound); HierarchyReferencesTab.AutoSelectHierarchyReference = entry.reference; } } MaintainerWindow.ClearNotification(); } } else { MaintainerWindow.ClearNotification(); } } Debug.Log(Maintainer.LogPrefix + ReferencesFinder.ModuleName + " results: " + referencesFound + " references found in " + sw.Elapsed.TotalSeconds.ToString("0.000", CultureInfo.InvariantCulture) + " seconds."); } else { Debug.Log(Maintainer.LogPrefix + ReferencesFinder.ModuleName + "Search canceled by user!"); } } catch (Exception e) { Debug.LogError(Maintainer.LogPrefix + ReferencesFinder.ModuleName + ": " + e); EditorUtility.ClearProgressBar(); } var foundObjects = GetFoundObjects(allObjects, results); SaveLastSearched(foundObjects); EntryGenerator.ResetCachedObjects(); SearchResultsStorage.HierarchyReferencesSearchResults = results.ToArray(); if (showResults) { MaintainerWindow.ShowObjectReferences(); } return(results.ToArray()); }
public static ProjectReferenceItem[] FindAssetsReferences(FilterItem[] allTargetAssets, FilterItem[] newTargetAssets, bool showResults = true) { var results = new List <ProjectReferenceItem>(); ConjunctionInfoList.Clear(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); try { var sw = Stopwatch.StartNew(); CSEditorTools.lastRevealSceneOpenResult = null; EntryGenerator.ResetCachedObjects(); var searchCanceled = LookForAssetsReferences(allTargetAssets, results); sw.Stop(); EditorUtility.ClearProgressBar(); if (!searchCanceled) { var resultsCount = results.Count; if (resultsCount <= 1) { ProjectReferencesTab.AutoSelectPath = null; MaintainerWindow.ShowNotification("Nothing found!"); } else { if (newTargetAssets != null && newTargetAssets.Length > 0) { var found = false; foreach (var result in results) { if (result.depth == 0 && CSFilterTools.IsValueMatchesAnyFilter(result.assetPath, newTargetAssets)) { found = true; break; } } if (!found) { ProjectReferencesTab.AutoSelectPath = null; MaintainerWindow.ShowNotification("Nothing found!"); } else { MaintainerWindow.ClearNotification(); } } else { MaintainerWindow.ClearNotification(); } } Debug.Log(Maintainer.LogPrefix + ReferencesFinder.ModuleName + " results: " + (resultsCount - 1) + " items found in " + sw.Elapsed.TotalSeconds.ToString("0.000", CultureInfo.InvariantCulture) + " seconds."); } else { Debug.Log(Maintainer.LogPrefix + ReferencesFinder.ModuleName + "Search canceled by user!"); } } catch (Exception e) { Debug.LogError(Maintainer.LogPrefix + ReferencesFinder.ModuleName + ": " + e); EditorUtility.ClearProgressBar(); } SaveLastSearched(results); EntryGenerator.ResetCachedObjects(); SearchResultsStorage.ProjectReferencesSearchResults = results.ToArray(); if (showResults) { MaintainerWindow.ShowAssetReferences(); } return(results.ToArray()); }