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); }
internal override FixResult PerformFix(bool batchMode) { FixResult result; 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) { result = new FixResult(false); if (batchMode) { Debug.LogWarning(Maintainer.LogPrefix + "Couldn't find settings asset for issue:\n" + this); } else { result.SetErrorText("Couldn't find settings asset at\n" + Path); } return(result); } result = IssuesFixer.FixMissingReference(assetObject, PropertyPath, RecordLocation.Asset); return(result); }
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); }
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 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) { 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); }
internal override FixResult PerformFix(bool batchMode) { FixResult result; var scriptableObjectAsset = AssetDatabase.LoadMainAssetAtPath(Path); if (scriptableObjectAsset == null) { result = new FixResult(false); if (batchMode) { Debug.LogWarning(Maintainer.LogPrefix + "Can't find Scriptable Object for issue:\n" + this); } else { result.SetErrorText("Couldn't find Scriptable Object\n" + Path); } return(result); } result = IssuesFixer.FixMissingReference(scriptableObjectAsset, propertyPath, RecordLocation.Asset); 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); }
/// <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 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); }