void IShowableRecord.Show() { if (!CSSelectionTools.RevealAndSelectFileAsset(assetDatabasePath)) { MaintainerWindow.ShowNotification("Can't show it properly"); } }
public void Show() { if (!CSSelectionTools.RevealAndSelectFileAsset(Path)) { MaintainerWindow.ShowNotification("Can't show it properly"); } }
public void Show() { if (!CSSelectionTools.RevealAndSelectGameObject(Path, transformPath, objectId, componentIndex)) { MaintainerWindow.ShowNotification("Can't show it properly"); } }
protected override bool PerformFix(bool batchMode) { var assetObject = AssetDatabase.LoadMainAssetAtPath(Path); // workaround for Unity 5.6 issue: LoadMainAssetAtPath returns null for settings assets if (assetObject == null) { var allObjects = AssetDatabase.LoadAllAssetsAtPath(Path); if (allObjects != null && allObjects.Length > 0) { assetObject = allObjects[0]; } } if (assetObject == null) { if (batchMode) { Debug.LogWarning(Maintainer.LogPrefix + "Couldn't find settings asset for issue:\n" + this); } else { MaintainerWindow.ShowNotification("Couldn't find settings asset at " + Path); } return(false); } var fixResult = IssuesFixer.FixMissingReference(assetObject, PropertyPath, RecordLocation.Asset); return(fixResult); }
protected override bool PerformFix(bool batchMode) { Object obj = null; Component component = null; CSSceneTools.OpenSceneResult openSceneResult = null; if (!batchMode && Location == RecordLocation.Scene) { openSceneResult = CSSceneTools.OpenScene(Path); if (!openSceneResult.success) { return(false); } } obj = GetObjectWithThisIssue(); if (obj == null) { if (batchMode) { Debug.LogWarning(Maintainer.LogPrefix + "Can't find Object for issue:\n" + this); } else { MaintainerWindow.ShowNotification("Couldn't find Object " + transformPath); } return(false); } if (!string.IsNullOrEmpty(componentName) && obj is GameObject) { component = GetComponentWithThisIssue(obj as GameObject); if (component == null) { if (batchMode) { Debug.LogWarning(Maintainer.LogPrefix + "Can't find component for issue:\n" + this); } else { MaintainerWindow.ShowNotification("Can't find component " + componentName); } return(false); } } var fixResult = IssuesFixer.FixObjectIssue(this, obj, component, Kind); if (!batchMode && Location == RecordLocation.Scene && openSceneResult != null) { CSSceneTools.SaveScene(openSceneResult.scene); CSSceneTools.CloseOpenedSceneIfNeeded(openSceneResult); } return(fixResult); }
/// <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); }
/// <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 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()); }
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()); }
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 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); } }
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(); } }