/// <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()); }
public void Show() { GameObject[] allObjects; if (location == RecordLocation.Scene) { if (CSSceneTools.GetCurrentScenePath() != path) { if (!CSSceneTools.SaveCurrentSceneIfUserWantsTo()) { return; } CSSceneTools.OpenScene(path); } allObjects = CSEditorTools.GetAllSuitableGameObjectsInCurrentScene(); CSEditorTools.PingObjectDelayed(AssetDatabase.LoadAssetAtPath(path, typeof(Object))); } else { List <GameObject> prefabs = new List <GameObject>(); CSEditorTools.GetAllSuitableGameObjectsInPrefabAssets(prefabs); allObjects = prefabs.ToArray(); } GameObject go = FindObjectInCollection(allObjects); if (go != null) { if (location == RecordLocation.Scene) { Selection.activeTransform = go.transform; } else { Selection.activeGameObject = go; if (gameObjectPath.Split('/').Length > 2) { CSEditorTools.PingObjectDelayed(AssetDatabase.LoadAssetAtPath(path, typeof(Object))); } } } else { MaintainerWindow.ShowNotification("Can't find object " + gameObjectPath); } }
protected override bool PerformFix(bool batchMode) { GameObject go = null; Component component = null; if (OpenNeededSceneIfNecessary(!batchMode)) { go = GetGameObjectWithThisIssue(); } if (go == null) { if (batchMode) { Debug.LogWarning(Maintainer.LOG_PREFIX + "Can't find Game Object for issue:\n" + this); } else { MaintainerWindow.ShowNotification("Couldn't find Game Object " + gameObjectPath); } return(false); } if (!string.IsNullOrEmpty(componentName)) { component = GetComponentWithThisIssue(go); if (component == null) { if (batchMode) { Debug.LogWarning(Maintainer.LOG_PREFIX + "Can't find component for issue:\n" + this); } else { MaintainerWindow.ShowNotification("Can't find component " + componentName); } return(false); } } return(IssuesFixer.FixGameObjectIssue(this, go, component, type)); }
protected override bool PerformFix(bool batchMode) { var scriptableObjectAsset = AssetDatabase.LoadMainAssetAtPath(Path); if (scriptableObjectAsset == null) { if (batchMode) { Debug.LogWarning(Maintainer.LogPrefix + "Can't find Scriptable Object for issue:\n" + this); } else { MaintainerWindow.ShowNotification("Couldn't find Scriptable Object\n" + Path); } return(false); } var fixResult = IssuesFixer.FixMissingReference(scriptableObjectAsset, propertyPath, RecordLocation.Asset); return(fixResult); }
protected override bool PerformFix(bool batchMode) { CSSceneTools.OpenSceneResult openSceneResult = null; if (!batchMode) { openSceneResult = CSSceneTools.OpenScene(Path); if (!openSceneResult.success) { return(false); } } var settingsObject = GetSettingsObjectWithThisIssue(); if (settingsObject == null) { if (batchMode) { Debug.LogWarning(Maintainer.LogPrefix + "Couldn't find " + SettingsKind + " object for issue:\n" + this); } else { MaintainerWindow.ShowNotification("Couldn't find " + SettingsKind + " object at " + Path); } return(false); } var fixResult = IssuesFixer.FixMissingReference(settingsObject, PropertyPath, RecordLocation.Scene); if (!batchMode) { CSSceneTools.SaveScene(openSceneResult.scene); CSSceneTools.CloseOpenedSceneIfNeeded(openSceneResult); } return(fixResult); }
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()); }
/// <summary> /// Starts garbage search with current settings. /// </summary> /// <param name="showResults">Shows results in %Maintainer window if true.</param> /// <returns>Array of CleanerRecords in case you wish to manually iterate over them and make custom report.</returns> public static CleanerRecord[] StartSearch(bool showResults) { List <CleanerRecord> results = new List <CleanerRecord>(); phasesCount = 0; currentPhase = 0; if (MaintainerSettings.Cleaner.findEmptyFolders) { phasesCount++; } if (MaintainerSettings.Cleaner.findEmptyScenes) { if (!CSSceneTools.SaveCurrentSceneIfUserWantsTo()) { Debug.Log(Maintainer.LOG_PREFIX + "Search canceled by user!"); return(null); } phasesCount++; searchStartScene = CSSceneTools.GetCurrentScenePath(true); } Stopwatch sw = Stopwatch.StartNew(); bool searchCanceled = false; if (MaintainerSettings.Cleaner.findEmptyFolders) { searchCanceled = !ScanFolders(results); } if (MaintainerSettings.Cleaner.findEmptyScenes) { searchCanceled = !ScanSceneFiles(results); } sw.Stop(); // opening scene where we started scan if (MaintainerSettings.Cleaner.findEmptyScenes) { if (string.IsNullOrEmpty(searchStartScene)) { CSSceneTools.NewScene(); } else if (CSSceneTools.GetCurrentScenePath() != searchStartScene) { CSSceneTools.OpenScene(searchStartScene); } } EditorUtility.ClearProgressBar(); if (!searchCanceled) { Debug.Log(Maintainer.LOG_PREFIX + MODULE_NAME + " results: " + results.Count + " items found in " + sw.Elapsed.TotalSeconds.ToString("0.000") + " seconds."); } else { Debug.Log(Maintainer.LOG_PREFIX + "Search canceled by user!"); } SearchResultsStorage.CleanerSearchResults = results.ToArray(); if (showResults) { MaintainerWindow.ShowCleaner(); } return(results.ToArray()); }
/// <summary> /// Starts clean of the garbage found with StartSearch() method. /// </summary> /// <param name="recordsToClean">Pass records you wish to clean here or leave null to let it load last search results.</param> /// <param name="showResults">Shows results in the %Maintainer window if true.</param> /// <param name="showConfirmation">Shows confirmation dialog before performing cleanup if true.</param> /// <returns>Array of CleanRecords which were cleaned up.</returns> public static CleanerRecord[] StartClean(CleanerRecord[] recordsToClean = null, bool showResults = true, bool showConfirmation = true) { var records = recordsToClean; if (records == null) { records = SearchResultsStorage.CleanerSearchResults; } if (records.Length == 0) { return(null); } cleanedBytes = 0; itemsToClean = 0; foreach (var record in records) { if (record.selected) { itemsToClean++; } } if (itemsToClean == 0) { EditorUtility.DisplayDialog(ModuleName, "Please select items to clean up!", "Ok"); return(null); } if (!showConfirmation || itemsToClean == 1 || EditorUtility.DisplayDialog("Confirmation", "Do you really wish to delete " + itemsToClean + " items?\n" + Maintainer.DataLossWarning, "Go for it!", "Cancel")) { var sw = System.Diagnostics.Stopwatch.StartNew(); var cleanCanceled = CleanRecords(records); var cleanedRecords = new List <CleanerRecord>(records.Length); var notCleanedRecords = new List <CleanerRecord>(records.Length); foreach (var record in records) { if (record.cleaned) { cleanedRecords.Add(record); } else { notCleanedRecords.Add(record); } } records = notCleanedRecords.ToArray(); sw.Stop(); EditorUtility.ClearProgressBar(); if (!cleanCanceled) { Debug.Log(Maintainer.LogPrefix + ModuleName + " results: " + cleanedRecords.Count + " items (" + CSEditorTools.FormatBytes(cleanedBytes) + " in size) cleaned in " + sw.Elapsed.TotalSeconds.ToString("0.000") + " seconds."); } else { Debug.Log(Maintainer.LogPrefix + "Deletion was canceled by user!"); } SearchResultsStorage.CleanerSearchResults = records; if (showResults) { MaintainerWindow.ShowCleaner(); } return(cleanedRecords.ToArray()); } return(null); }
/// <summary> /// Starts garbage search with current settings. /// </summary> /// <param name="showResults">Shows results in %Maintainer window if true.</param> /// <returns>Array of CleanerRecords in case you wish to manually iterate over them and make custom report.</returns> public static CleanerRecord[] StartSearch(bool showResults) { var results = new List <CleanerRecord>(); phasesCount = 0; currentPhase = 0; if (MaintainerSettings.Cleaner.findEmptyFolders) { phasesCount++; } if (MaintainerSettings.Cleaner.findUnreferencedAssets) { phasesCount++; } var searchCanceled = !CSSceneTools.SaveCurrentModifiedScenes(true); if (searchCanceled) { Debug.Log(Maintainer.LogPrefix + "Search canceled by user!"); return(null); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); try { var sw = System.Diagnostics.Stopwatch.StartNew(); CSEditorTools.lastRevealSceneOpenResult = null; if (MaintainerSettings.Cleaner.findEmptyFolders) { searchCanceled = ScanFolders(results); } if (!searchCanceled && MaintainerSettings.Cleaner.findUnreferencedAssets) { searchCanceled = ScanProjectFiles(results); } sw.Stop(); EditorUtility.ClearProgressBar(); if (!searchCanceled) { Debug.Log(Maintainer.LogPrefix + ModuleName + " results: " + results.Count + " items found in " + sw.Elapsed.TotalSeconds.ToString("0.000") + " seconds."); } else { Debug.Log(Maintainer.LogPrefix + "Search canceled by user!"); } } catch (Exception e) { Debug.Log(Maintainer.LogPrefix + e); EditorUtility.ClearProgressBar(); } SearchResultsStorage.CleanerSearchResults = results.ToArray(); if (showResults) { MaintainerWindow.ShowCleaner(); } return(results.ToArray()); }
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 HierarchyReferenceItem[] FindObjectsReferencesInHierarchy(Object[] objects, bool checkGameObjectsComponents, bool showResults = true) { if (UserSettings.References.clearHierarchyResults) { SearchResultsStorage.HierarchyReferencesLastSearched = new int[0]; SearchResultsStorage.HierarchyReferencesSearchResults = new HierarchyReferenceItem[0]; } var lastSearched = SearchResultsStorage.HierarchyReferencesLastSearched; var allObjects = CSObjectTools.GetObjectsFromInstanceIds(lastSearched); var items = new List <Object>(objects); if (checkGameObjectsComponents) { for (var i = items.Count - 1; i >= 0; i--) { var item = items[i]; var gameObject = item as GameObject; if (gameObject == null) { continue; } var components = gameObject.GetComponents <Component>(); foreach (var component in components) { if (component == null) { continue; } if (CSObjectTools.IsHiddenInInspector(component)) { continue; } items.Insert(i, component); } } } var newItem = false; foreach (var o in items) { if (!ArrayUtility.Contains(allObjects, o)) { newItem = true; ArrayUtility.Add(ref allObjects, o); } } if (items.Count == 1) { HierarchyReferencesTab.AutoSelectHierarchyReference = ObjectToReferencingEntry(items[0]).reference; } HierarchyReferenceItem[] result; if (newItem) { result = FindHierarchyObjectsReferences(allObjects, items.ToArray(), showResults); } else { MaintainerWindow.ShowObjectReferences(); result = SearchResultsStorage.HierarchyReferencesSearchResults; } return(result); }
private static void ShowWindow() { MaintainerWindow.Create(); }
public void Show() { GameObject go = null; if (OpenNeededSceneIfNecessary(true)) { go = GetGameObjectWithThisIssue(); } if (go != null) { CSObjectTools.SelectGameObject(go, location); if (location == RecordLocation.Scene) { EditorApplication.delayCall += () => { EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(path, typeof(Object))); }; } else { if (gameObjectPath.Split('/').Length > 2) { EditorApplication.delayCall += () => { EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(path, typeof(Object))); }; } } ActiveEditorTracker tracker = CSEditorTools.GetActiveEditorTrackerForSelectedObject(); tracker.RebuildIfNecessary(); Editor[] editors = tracker.activeEditors; long[] ids = new long[editors.Length]; bool targetFound = false; for (int i = 0; i < editors.Length; i++) { Editor editor = editors[i]; long id = CSObjectTools.GetLocalIdentifierInFileForObject(editor.serializedObject.targetObject); ids[i] = id; if (id == componentId) { targetFound = true; /* known corner cases when editor can't be set to visible via tracker */ if (editor.serializedObject.targetObject is ParticleSystemRenderer) { ParticleSystemRenderer renderer = (ParticleSystemRenderer)editor.serializedObject.targetObject; ParticleSystem ps = renderer.GetComponent <ParticleSystem>(); componentId = CSObjectTools.GetLocalIdentifierInFileForObject(ps); } } } if (targetFound) { for (int i = 0; i < editors.Length; i++) { tracker.SetVisible(i, ids[i] != componentId ? 0 : 1); } } } else { MaintainerWindow.ShowNotification("Couldn't find object " + gameObjectPath); } }
/// <summary> /// Starts fix of the issues found with StartSearch() method. /// </summary> /// <param name="recordsToFix">Pass records you wish to fix here or leave null to let it load last search results.</param> /// <param name="showResults">Shows results in the %Maintainer window if true.</param> /// <param name="showConfirmation">Shows confirmation dialog before performing fix if true.</param> /// <returns>Array of IssueRecords which were fixed up.</returns> public static IssueRecord[] StartFix(IssueRecord[] recordsToFix = null, bool showResults = true, bool showConfirmation = true) { var records = recordsToFix; if (records == null) { records = SearchResultsStorage.IssuesSearchResults; } if (records.Length == 0) { Debug.Log(Maintainer.LogPrefix + "Nothing to fix!"); return(null); } recordsToFixCount = 0; foreach (var record in records) { if (record.selected) { recordsToFixCount++; } } if (recordsToFixCount == 0) { EditorUtility.DisplayDialog(ModuleName, "Please select issues to fix!", "Ok"); return(null); } if (!CSSceneTools.SaveCurrentModifiedScenes(false)) { Debug.Log(Maintainer.LogPrefix + "Issues batch fix canceled by user!"); return(null); } if (showConfirmation && !EditorUtility.DisplayDialog("Confirmation", "Do you really wish to let Maintainer automatically fix " + recordsToFixCount + " issues?\n" + Maintainer.DataLossWarning, "Go for it!", "Cancel")) { return(null); } var fixedRecords = new List <IssueRecord>(records.Length); var notFixedRecords = new List <IssueRecord>(records.Length); PrepareToBatchOperation(); try { var sw = Stopwatch.StartNew(); lastOpenSceneResult = null; CSEditorTools.lastRevealSceneOpenResult = null; IssuesFixer.FixRecords(records); foreach (var record in records) { if (record.fixResult != null && record.fixResult.Success) { fixedRecords.Add(record); } else { notFixedRecords.Add(record); } } records = notFixedRecords.ToArray(); sw.Stop(); if (!operationCanceled) { var results = fixedRecords.Count + " issues fixed in " + sw.Elapsed.TotalSeconds.ToString("0.000") + " seconds"; Debug.Log(Maintainer.LogPrefix + ModuleName + " results: " + results); MaintainerWindow.ShowNotification(results); } else { Debug.Log(Maintainer.LogPrefix + "Fix canceled by user!"); } if (lastOpenSceneResult != null) { CSSceneTools.SaveScene(lastOpenSceneResult.scene); CSSceneTools.CloseOpenedSceneIfNeeded(lastOpenSceneResult); lastOpenSceneResult = null; } SearchResultsStorage.IssuesSearchResults = records; if (showResults) { MaintainerWindow.ShowIssues(); } } catch (Exception e) { Debug.LogError(Maintainer.LogPrefix + ModuleName + ": something went wrong :(\n" + e); } EditorUtility.ClearProgressBar(); return(fixedRecords.ToArray()); }
/// <summary> /// Starts clean of the garbage found with StartSearch() method. /// </summary> /// <param name="recordsToClean">Pass records you wish to clean here or leave null to let it load last search results.</param> /// <param name="showResults">Shows results in the %Maintainer window if true.</param> /// <param name="showConfirmation">Shows confirmation dialog before performing cleanup if true.</param> /// <returns>Array of CleanRecords which were cleaned up.</returns> public static CleanerRecord[] StartClean(CleanerRecord[] recordsToClean = null, bool showResults = true, bool showConfirmation = true) { CleanerRecord[] records = recordsToClean; if (records == null) { records = SearchResultsStorage.CleanerSearchResults; } if (records.Length == 0) { return(null); } itemsToClean = 0; foreach (CleanerRecord record in records) { if (record.selected) { itemsToClean++; } } if (itemsToClean == 0) { EditorUtility.DisplayDialog(MODULE_NAME, "Please select items to clean up!", "Ok"); return(null); } if (!showConfirmation || EditorUtility.DisplayDialog("Confirmation", "Do you really wish to delete " + itemsToClean + " items?\n" + DATA_LOSS_WARNING, "Go for it!", "Cancel")) { Stopwatch sw = Stopwatch.StartNew(); bool cleanCanceled = CleanRecords(records); List <CleanerRecord> cleanedRecords = new List <CleanerRecord>(records.Length); List <CleanerRecord> notCleanedRecords = new List <CleanerRecord>(records.Length); foreach (CleanerRecord record in records) { if (record.cleaned) { cleanedRecords.Add(record); } else { notCleanedRecords.Add(record); } } records = notCleanedRecords.ToArray(); sw.Stop(); EditorUtility.ClearProgressBar(); if (!cleanCanceled) { Debug.Log(Maintainer.LOG_PREFIX + MODULE_NAME + " results: " + itemsToClean + " items cleaned in " + sw.Elapsed.TotalSeconds.ToString("0.000") + " seconds."); } else { Debug.Log(Maintainer.LOG_PREFIX + "Clean canceled by user!"); } SearchResultsStorage.CleanerSearchResults = records; if (showResults) { MaintainerWindow.ShowCleaner(); } return(cleanedRecords.ToArray()); } return(null); }
protected ReferencesChildTab(MaintainerWindow window) : base(window) { }
/// <summary> /// Starts search with current settings. /// </summary> /// <param name="showResults">Shows results in the %Maintainer window if true.</param> /// <returns>Array of IssueRecords in case you wish to manually iterate over them and make custom report.</returns> public static IssueRecord[] StartSearch(bool showResults) { phasesCount = 0; if (MaintainerSettings.Issues.scanGameObjects && MaintainerSettings.Issues.lookInScenes) { if (MaintainerSettings.Issues.scenesSelection != IssuesFinderSettings.ScenesSelection.CurrentSceneOnly) { if (!CSSceneTools.SaveCurrentSceneIfUserWantsTo()) { Debug.Log(Maintainer.LOG_PREFIX + "Issues search canceled by user!"); return(null); } searchStartScene = CSSceneTools.GetCurrentScenePath(true); } else { searchStartScene = CSSceneTools.GetCurrentScenePath(); } } List <IssueRecord> issues = new List <IssueRecord>(); Stopwatch sw = Stopwatch.StartNew(); try { CollectInput(); bool searchCanceled = false; if (MaintainerSettings.Issues.scanGameObjects) { if (MaintainerSettings.Issues.lookInScenes) { searchCanceled = !ProcessSelectedScenes(issues); } if (!searchCanceled && MaintainerSettings.Issues.lookInAssets) { searchCanceled = !ProcessPrefabFiles(issues); } } if (MaintainerSettings.Issues.scanProjectSettings) { if (!searchCanceled) { searchCanceled = !ProcessSettings(issues); } } sw.Stop(); if (!searchCanceled) { Debug.Log(Maintainer.LOG_PREFIX + MODULE_NAME + " results: " + issues.Count + " issues in " + sw.Elapsed.TotalSeconds.ToString("0.000") + " seconds, " + scenesCount + " scenes and " + prefabsCount + " prefabs scanned."); } else { Debug.Log(Maintainer.LOG_PREFIX + "Search canceled by user!"); } SearchResultsStorage.IssuesSearchResults = issues.ToArray(); if (showResults) { MaintainerWindow.ShowIssues(); } } catch (Exception e) { Debug.LogError(Maintainer.LOG_PREFIX + MODULE_NAME + ": something went wrong :(\n" + e); } FinishSearch(); return(issues.ToArray()); }
/// <summary> /// Starts garbage search with current settings. /// </summary> /// <param name="showResults">Shows results in %Maintainer window if true.</param> /// <returns>Array of CleanerRecords in case you wish to manually iterate over them and make custom report.</returns> public static CleanerRecord[] StartSearch(bool showResults) { List <CleanerRecord> results = new List <CleanerRecord>(); phasesCount = 0; currentPhase = 0; if (MaintainerSettings.Cleaner.findEmptyFolders) { phasesCount++; } if (MaintainerSettings.Cleaner.findUnusedAssets) { phasesCount++; } bool searchCanceled = false; AssetDatabase.SaveAssets(); try { Stopwatch sw = Stopwatch.StartNew(); if (MaintainerSettings.Cleaner.findEmptyFolders) { searchCanceled = ScanFolders(results); } if (!searchCanceled && MaintainerSettings.Cleaner.findUnusedAssets) { searchCanceled = ScanProjectFiles(results); } sw.Stop(); EditorUtility.ClearProgressBar(); if (!searchCanceled) { Debug.Log(Maintainer.LOG_PREFIX + MODULE_NAME + " results: " + results.Count + " items found in " + sw.Elapsed.TotalSeconds.ToString("0.000") + " seconds."); } else { Debug.Log(Maintainer.LOG_PREFIX + "Search canceled by user!"); } } catch (Exception e) { Debug.Log(e); EditorUtility.ClearProgressBar(); } SearchResultsStorage.CleanerSearchResults = results.ToArray(); if (showResults) { MaintainerWindow.ShowCleaner(); } return(results.ToArray()); }
/// <summary> /// Starts search with current settings. /// </summary> /// <param name="showResults">Shows results in the %Maintainer window if true.</param> /// <returns>Array of IssueRecords in case you wish to manually iterate over them and make custom report.</returns> public static IssueRecord[] StartSearch(bool showResults) { if (!ProjectSettings.Issues.lookInScenes && !ProjectSettings.Issues.lookInAssets && !ProjectSettings.Issues.lookInProjectSettings) { MaintainerWindow.ShowNotification("Nowhere to search!"); return(null); } if (ProjectSettings.Issues.lookInScenes) { if (!CSSceneTools.SaveCurrentModifiedScenes(false)) { Debug.Log(Maintainer.LogPrefix + "Issues search canceled by user!"); return(null); } } var issues = new List <IssueRecord>(); PrepareToBatchOperation(); try { var sw = Stopwatch.StartNew(); CSTraverseTools.ClearStats(); var targetAssets = TargetCollector.CollectTargetAssets(); /*foreach (var targetAsset in targetAssets) * { * Debug.Log(targetAsset.Path); * }*/ TargetProcessor.SetIssuesList(issues); TargetProcessor.ProcessTargetAssets(targetAssets); var traverseStats = CSTraverseTools.GetStats(); var checkedAssets = targetAssets.Length; sw.Stop(); if (!operationCanceled) { var result = string.Format(CultureInfo.InvariantCulture, Maintainer.LogPrefix + ModuleName + " found issues: {0}\n" + "Seconds: {1:0.000}; Assets: {2}; Game Objects: {3}; Components: {4}; Properties: {5}", issues.Count, sw.Elapsed.TotalSeconds, checkedAssets, traverseStats.gameObjectsTraversed, traverseStats.componentsTraversed, traverseStats.propertiesTraversed); Debug.Log(result); } else { Debug.Log(Maintainer.LogPrefix + "Search canceled by user!"); } SearchResultsStorage.IssuesSearchResults = issues.ToArray(); if (showResults) { MaintainerWindow.ShowIssues(); } } catch (Exception e) { Debug.LogError(Maintainer.LogPrefix + ModuleName + ": something went wrong :(\n" + e); } EditorUtility.ClearProgressBar(); return(issues.ToArray()); }
/// <summary> /// Starts search with current settings and either show %Maintainer window or not, /// depending on showResults param. /// </summary> /// <param name="showResults">Shows results in %Maintainer window if true.</param> /// <returns>Array of IssueRecords in case you wish to manually iterate over them and make custom report.</returns> public static IssueRecord[] StartSearch(bool showResults) { if (MaintainerSettings.Issues.lookInScenes) { if (MaintainerSettings.Issues.scenesSelection != IssuesSettings.ScenesSelection.CurrentSceneOnly) { if (!EditorApplication.SaveCurrentSceneIfUserWantsTo()) { Debug.Log(Maintainer.LOG_PREFIX + "Issues search cancelled by user!"); return(null); } } } searchStartScene = EditorApplication.currentScene; List <IssueRecord> issues = new List <IssueRecord>(); Stopwatch sw = Stopwatch.StartNew(); try { CollectInput(); bool searchCancelled = false; if (MaintainerSettings.Issues.lookInScenes) { List <IssueRecord> allScenesIssues = ProcessAllScenes(); if (allScenesIssues != null) { issues.AddRange(allScenesIssues); } else { searchCancelled = true; } } if (!searchCancelled && MaintainerSettings.Issues.lookInAssets) { List <IssueRecord> allPrefabsIssues = ProcessPrefabFiles(); if (allPrefabsIssues != null) { issues.AddRange(allPrefabsIssues); } else { searchCancelled = true; } } sw.Stop(); if (!searchCancelled) { Debug.Log(Maintainer.LOG_PREFIX + " Issues Finder results: " + issues.Count + " issues in " + sw.Elapsed.TotalSeconds.ToString("0.000") + " seconds"); MaintainerSettings.Issues.lastSearchResults = issues.ToArray(); EditorUtility.SetDirty(MaintainerSettings.Instance); if (showResults) { MaintainerWindow.ShowIssues(); } } else { Debug.Log(Maintainer.LOG_PREFIX + " Search cancelled by user!"); issues.Add(new IssueRecord("Search cancelled by user!")); } } catch (Exception e) { Debug.LogError(Maintainer.LOG_PREFIX + " Something went wrong :( Error: " + e); issues.Add(new IssueRecord("Something went wrong :( Error: " + e)); } FinishSearch(); return(issues.ToArray()); }
private static void ShowAbout() { MaintainerWindow.ShowAbout(); }
public static void RevealAndSelectReferencingEntry(string assetPath, ReferencingEntryData referencingEntry) { if (!string.IsNullOrEmpty(assetPath) && (referencingEntry.location == Location.SceneLightingSettings || referencingEntry.location == Location.SceneNavigationSettings)) { var sceneOpenResult = CSSceneTools.OpenSceneWithSavePrompt(assetPath); if (!sceneOpenResult.success) { Debug.LogError(Maintainer.ConstructError("Can't open scene " + assetPath)); MaintainerWindow.ShowNotification("Can't show it properly"); return; } } switch (referencingEntry.location) { case Location.ScriptAsset: case Location.ScriptableObjectAsset: if (!RevealAndSelectFileAsset(assetPath)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.PrefabAssetObject: if (!RevealAndSelectSubAsset(assetPath, referencingEntry.transformPath, referencingEntry.objectId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.PrefabAssetGameObject: case Location.SceneGameObject: if (!RevealAndSelectGameObject(assetPath, referencingEntry.transformPath, referencingEntry.objectId, referencingEntry.componentId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.SceneLightingSettings: if (!CSMenuTools.ShowSceneSettingsLighting()) { Debug.LogError(Maintainer.ConstructError("Can't open Lighting settings!")); MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.SceneNavigationSettings: if (!CSMenuTools.ShowSceneSettingsNavigation()) { Debug.LogError(Maintainer.ConstructError("Can't open Navigation settings!")); MaintainerWindow.ShowNotification("Can't show it properly"); } break; case Location.NotFound: case Location.Invisible: break; case Location.TileMap: if (!RevealAndSelectGameObject(assetPath, referencingEntry.transformPath, referencingEntry.objectId, referencingEntry.componentId)) { MaintainerWindow.ShowNotification("Can't show it properly"); } // TODO: open tile map editor window? break; default: throw new ArgumentOutOfRangeException(); } }