/// <summary> /// Adds new assets to the last selection if it existed and calls a GetReferences() with extended selection; /// </summary> /// <param name="selectedAssets">Additionally selected assets.</param> /// <param name="showResults">Shows results in %Maintainer window if true.</param> /// <returns>Array of ReferencesTreeElement for the TreeView buildup or manual parsing.</returns> public static ReferencesTreeElement[] AddToSelectionAndRun(FilterItem[] selectedAssets, bool showResults = true) { if (MaintainerPersonalSettings.References.selectedFindClearsResults) { SearchResultsStorage.ReferencesSearchSelection = new FilterItem[0]; SearchResultsStorage.ReferencesSearchResults = new ReferencesTreeElement[0]; } var currentSelection = SearchResultsStorage.ReferencesSearchSelection; var newItem = false; foreach (var selectedAsset in selectedAssets) { newItem |= CSFilterTools.TryAddNewItemToFilters(ref currentSelection, selectedAsset); } if (selectedAssets.Length == 1) { ReferencesTab.AutoSelectPath = selectedAssets[0].value; } if (newItem) { return(GetReferences(currentSelection, showResults)); } ReferencesTab.AutoShowExistsNotification = true; MaintainerWindow.ShowReferences(); return(SearchResultsStorage.ReferencesSearchResults); }
internal static ReferencesTreeElement[] FindAssetsReferences(FilterItem[] assets, bool ignoreClearOption, bool showResults) { if (MaintainerPersonalSettings.References.selectedFindClearsResults && !ignoreClearOption) { SearchResultsStorage.ReferencesFinderLastSearched = new FilterItem[0]; SearchResultsStorage.ReferencesSearchResults = new ReferencesTreeElement[0]; } var lastSearched = SearchResultsStorage.ReferencesFinderLastSearched; var newItem = false; foreach (var asset in assets) { newItem |= CSFilterTools.TryAddNewItemToFilters(ref lastSearched, asset); } if (assets.Length == 1) { ReferencesTab.AutoSelectPath = assets[0].value; } if (newItem) { return(GetReferences(lastSearched, assets, showResults)); } //ReferencesTab.AutoShowExistsNotification = true; MaintainerWindow.ShowReferences(); return(SearchResultsStorage.ReferencesSearchResults); }
/// <summary> /// Returns references of selectedAssets or all assets at the project (if selectedAssets is null), e.g. where each asset is referenced, with additional filtration of the results. /// </summary> /// <param name="selectedAssets">Assets you wish to show references for. Pass null to process all assets in the project.</param> /// <param name="showResults">Shows results in %Maintainer window if true.</param> /// <returns>Array of ReferencesTreeElement for the TreeView buildup or manual parsing.</returns> public static ReferencesTreeElement[] GetReferences(FilterItem[] selectedAssets, bool showResults = true) { var results = new List <ReferencesTreeElement>(); conjunctionInfoList.Clear(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); try { var sw = Stopwatch.StartNew(); CSEditorTools.lastRevealSceneOpenResult = null; var searchCanceled = LookForReferences(selectedAssets, results); sw.Stop(); EditorUtility.ClearProgressBar(); if (!searchCanceled) { var resultsCount = results.Count; if (resultsCount <= 1) { MaintainerWindow.ShowNotification("Nothing found!"); } Debug.Log(Maintainer.LogPrefix + ModuleName + " results: " + (resultsCount - 1) + " items found in " + sw.Elapsed.TotalSeconds.ToString("0.000", CultureInfo.InvariantCulture) + " seconds."); } else { Debug.Log(Maintainer.LogPrefix + ModuleName + "Search canceled by user!"); } } catch (Exception e) { Debug.LogError(Maintainer.LogPrefix + ModuleName + ": " + e); EditorUtility.ClearProgressBar(); } BuildSelectedAssetsFromResults(results); SearchResultsStorage.ReferencesSearchResults = results.ToArray(); if (showResults) { MaintainerWindow.ShowReferences(); } return(results.ToArray()); }
internal static ReferencesTreeElement[] GetReferences(FilterItem[] allTargetAssets, FilterItem[] newTargetAssets, bool showResults = true) { var results = new List <ReferencesTreeElement>(); ConjunctionInfoList.Clear(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); try { var sw = Stopwatch.StartNew(); CSEditorTools.lastRevealSceneOpenResult = null; var searchCanceled = LookForReferences(allTargetAssets, results); sw.Stop(); EditorUtility.ClearProgressBar(); if (!searchCanceled) { var resultsCount = results.Count; if (resultsCount <= 1) { ReferencesTab.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) { ReferencesTab.AutoSelectPath = null; MaintainerWindow.ShowNotification("Nothing found!"); } } Debug.Log(Maintainer.LogPrefix + ModuleName + " results: " + (resultsCount - 1) + " items found in " + sw.Elapsed.TotalSeconds.ToString("0.000", CultureInfo.InvariantCulture) + " seconds."); } else { Debug.Log(Maintainer.LogPrefix + ModuleName + "Search canceled by user!"); } } catch (Exception e) { Debug.LogError(Maintainer.LogPrefix + ModuleName + ": " + e); EditorUtility.ClearProgressBar(); } BuildSelectedAssetsFromResults(results); SearchResultsStorage.ReferencesSearchResults = results.ToArray(); if (showResults) { MaintainerWindow.ShowReferences(); } return(results.ToArray()); }