Beispiel #1
0
        /// <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());
        }
Beispiel #2
0
        /// <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());
        }
Beispiel #3
0
        /// <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 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());
        }