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); }
private static void ProcessSceneForProjectLevelReferences(string path, List <TreeConjunction> conjunctions) { var openSceneResult = CSSceneTools.OpenScene(path); if (!openSceneResult.success) { Debug.LogWarning(Maintainer.ConstructWarning("Can't open scene " + path)); return; } SceneSettingsProcessor.Process(conjunctions); EntryFinder.currentLocation = Location.SceneGameObject; CSTraverseTools.TraverseSceneGameObjects(openSceneResult.scene, true, false, EntryFinder.OnGameObjectTraverse); CSSceneTools.CloseOpenedSceneIfNeeded(openSceneResult); }
private static void ProcessScene() { var path = assetConjunctions.asset.Path; var openSceneResult = CSSceneTools.OpenScene(path); if (!openSceneResult.success) { Debug.LogWarning(Maintainer.ConstructWarning("Can't open scene " + path)); return; } SceneSettingsProcessor.Process(assetConjunctions.conjunctions); currentLocation = Location.SceneGameObject; CSTraverseTools.TraverseSceneGameObjects(openSceneResult.scene, true, OnGameObjectTraverse); CSSceneTools.CloseOpenedSceneIfNeeded(openSceneResult); }
protected override FixResult PerformFix(bool batchMode) { CSSceneTools.OpenSceneResult openSceneResult = null; if (!batchMode) { openSceneResult = CSSceneTools.OpenScene(Path); if (!openSceneResult.success) { return(FixResult.CreateError("Couldn't open scene")); } } FixResult result; var settingsObject = GetSettingsObjectWithThisIssue(); if (settingsObject == null) { result = new FixResult(false); if (batchMode) { Debug.LogWarning(Maintainer.LogPrefix + "Couldn't find " + SettingsKind + " object for issue:\n" + this); } else { result.SetErrorText("Couldn't find " + SettingsKind + " object at\n" + Path); } return(result); } result = IssuesFixer.FixMissingReference(settingsObject, PropertyPath, RecordLocation.Scene); if (!batchMode) { CSSceneTools.SaveScene(openSceneResult.scene); CSSceneTools.CloseOpenedSceneIfNeeded(openSceneResult); } return(result); }
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); }
private static void ProcessScene(AssetInfo asset, string assetName, int sceneIndex, int totalScenes) { currentObjectIndex = 0; itemIndex = sceneIndex; totalItems = totalScenes; currentAssetName = assetName; var openSceneResult = CSSceneTools.OpenScene(asset.Path); if (!openSceneResult.success) { Debug.LogWarning(Maintainer.ConstructWarning("Can't open scene " + asset.Path)); return; } var skipCleanPrefabInstances = ProjectSettings.Issues.scanGameObjects && ProjectSettings.Issues.lookInAssets; IssuesDetector.SceneStart(asset); CSTraverseTools.TraverseSceneGameObjects(openSceneResult.scene, skipCleanPrefabInstances, false, OnGameObjectTraverse); IssuesDetector.SceneEnd(asset); CSSceneTools.CloseOpenedSceneIfNeeded(openSceneResult); }
/// <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()); }
public static void FixRecords(IssueRecord[] results, bool showProgress = true) { var i = 0; var count = results.Length; var sortedRecords = results.OrderBy(RecordsSortings.issueRecordByPath).ToArray(); var updateStep = Math.Max(count / ProjectSettings.UpdateProgressStep, 1); for (var k = 0; k < count; k++) { var item = sortedRecords[k]; if (showProgress) { if (k % updateStep == 0) { if (IssuesFinder.ShowProgressBar(1, 1, i, count, "Resolving selected issues...")) { IssuesFinder.operationCanceled = true; break; } } } if (item.selected && item.IsFixable) { if (item.Location == RecordLocation.Scene) { var assetIssue = item as AssetIssueRecord; if (assetIssue != null) { var newOpenSceneResult = CSSceneTools.OpenScene(assetIssue.Path); if (!newOpenSceneResult.success) { continue; } if (newOpenSceneResult.sceneWasLoaded) { if (IssuesFinder.lastOpenSceneResult != null) { CSSceneTools.SaveScene(IssuesFinder.lastOpenSceneResult.scene); CSSceneTools.CloseOpenedSceneIfNeeded(IssuesFinder.lastOpenSceneResult); } } if (IssuesFinder.lastOpenSceneResult == null || IssuesFinder.lastOpenSceneResult.scene != newOpenSceneResult.scene) { IssuesFinder.lastOpenSceneResult = newOpenSceneResult; } } } item.Fix(true); i++; } } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
internal override FixResult PerformFix(bool batchMode) { Component component = null; FixResult result; CSSceneTools.OpenSceneResult openSceneResult = null; if (!batchMode && Location == RecordLocation.Scene) { openSceneResult = CSSceneTools.OpenScene(Path); if (!openSceneResult.success) { return(FixResult.CreateError("Couldn't open scene")); } } var obj = GetObjectWithThisIssue(); if (obj == null) { result = new FixResult(false); if (batchMode) { Debug.LogWarning(Maintainer.LogPrefix + "Can't find Object for issue:\n" + this); } else { result.SetErrorText("Couldn't find Object\n" + transformPath); } return(result); } if (!string.IsNullOrEmpty(componentName) && obj is GameObject) { component = GetComponentWithThisIssue(obj as GameObject); if (component == null) { result = new FixResult(false); if (batchMode) { Debug.LogWarning(Maintainer.LogPrefix + "Can't find component for issue:\n" + this); } else { result.SetErrorText("Can't find component\n" + componentName); } return(result); } } result = IssuesFixer.FixObjectIssue(this, obj, component, Kind); if (!batchMode && Location == RecordLocation.Scene && openSceneResult != null) { CSSceneTools.SaveScene(openSceneResult.scene); CSSceneTools.CloseOpenedSceneIfNeeded(openSceneResult); } return(result); }