예제 #1
0
        internal override bool MatchesFilter(FilterItem newFilter)
        {
            var filters = new[] { newFilter };

            switch (newFilter.kind)
            {
            case FilterKind.Path:
            case FilterKind.Directory:
            case FilterKind.FileName:
            case FilterKind.Extension:
                return(!string.IsNullOrEmpty(Path) && CSFilterTools.IsValueMatchesAnyFilterOfKind(Path, filters, newFilter.kind));

            case FilterKind.Type:
            {
                return(!string.IsNullOrEmpty(componentName) && CSFilterTools.IsValueMatchesAnyFilterOfKind(componentName, filters, newFilter.kind));
            }

            case FilterKind.NotSet:
                return(false);

            default:
                Debug.LogWarning(Maintainer.LogPrefix + "Unknown filter kind: " + newFilter.kind);
                return(false);
            }
        }
예제 #2
0
        internal static ReferencesTreeElement[] FindAssetsReferences(FilterItem[] assets, bool ignoreClearOption, bool showResults)
        {
            if (MaintainerPersonalSettings.References.selectedFindClearsResults && !ignoreClearOption)
            {
                SearchResultsStorage.ReferencesFinderLastSearched = new FilterItem[0];
                SearchResultsStorage.ReferencesSearchResults      = new ReferencesTreeElement[0];
            }

            var lastSearched = SearchResultsStorage.ReferencesFinderLastSearched;

            var newItem = false;

            foreach (var asset in assets)
            {
                newItem |= CSFilterTools.TryAddNewItemToFilters(ref lastSearched, asset);
            }

            if (assets.Length == 1)
            {
                ReferencesTab.AutoSelectPath = assets[0].value;
            }

            if (newItem)
            {
                return(GetReferences(lastSearched, assets, showResults));
            }

            //ReferencesTab.AutoShowExistsNotification = true;
            MaintainerWindow.ShowReferences();

            return(SearchResultsStorage.ReferencesSearchResults);
        }
예제 #3
0
        /// <summary>
        /// Adds new assets to the last selection if it existed and calls a GetReferences() with extended selection;
        /// </summary>
        /// <param name="selectedAssets">Additionally selected assets.</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[] AddToSelectionAndRun(FilterItem[] selectedAssets, bool showResults = true)
        {
            if (MaintainerPersonalSettings.References.selectedFindClearsResults)
            {
                SearchResultsStorage.ReferencesSearchSelection = new FilterItem[0];
                SearchResultsStorage.ReferencesSearchResults   = new ReferencesTreeElement[0];
            }

            var currentSelection = SearchResultsStorage.ReferencesSearchSelection;

            var newItem = false;

            foreach (var selectedAsset in selectedAssets)
            {
                newItem |= CSFilterTools.TryAddNewItemToFilters(ref currentSelection, selectedAsset);
            }

            if (selectedAssets.Length == 1)
            {
                ReferencesTab.AutoSelectPath = selectedAssets[0].value;
            }

            if (newItem)
            {
                return(GetReferences(currentSelection, showResults));
            }

            ReferencesTab.AutoShowExistsNotification = true;
            MaintainerWindow.ShowReferences();

            return(SearchResultsStorage.ReferencesSearchResults);
        }
예제 #4
0
        private static bool AssetIsFilteredOut(AssetInfo referencedAsset, int depth)
        {
            if (MaintainerPersonalSettings.References.showAssetsWithoutReferences || depth != 0)
            {
                return(false);
            }
            if (referencedAsset.referencedAtInfoList.Length == 0)
            {
                return(true);
            }

            var allIgnored = true;

            foreach (var referencedAtInfo in referencedAsset.referencedAtInfoList)
            {
                if (CSFilterTools.IsValueMatchesAnyFilter(referencedAtInfo.assetInfo.Path, MaintainerSettings.References.pathIgnoresFilters))
                {
                    continue;
                }
                if (referencedAtInfo.assetInfo.Kind == AssetKind.FromPackage)
                {
                    continue;
                }

                allIgnored = false;
                break;
            }

            return(allIgnored);
        }
        internal override void ProcessDrags()
        {
            if (currentEventType != EventType.DragUpdated && currentEventType != EventType.DragPerform)
            {
                return;
            }

            var paths = DragAndDrop.paths;

            if (paths != null && paths.Length > 0)
            {
                var canDrop = false;

                for (var i = 0; i < paths.Length; i++)
                {
                    paths[i] = CSPathTools.EnforceSlashes(paths[i]);
                    if (LooksLikeSceneFile(paths[i]))
                    {
                        canDrop = true;
                        break;
                    }
                }

                if (canDrop)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                    if (currentEventType == EventType.DragPerform)
                    {
                        var needToSave        = false;
                        var needToShowWarning = false;

                        foreach (var path in paths)
                        {
                            if (LooksLikeSceneFile(path))
                            {
                                var added = CSFilterTools.TryAddNewItemToFilters(ref filters, FilterItem.Create(path, FilterKind.Path));
                                needToSave        |= added;
                                needToShowWarning |= !added;
                            }
                        }

                        if (needToSave)
                        {
                            SaveChanges();
                        }

                        if (needToShowWarning)
                        {
                            window.ShowNotification(new GUIContent("One or more of the dragged items already present in the list!"));
                        }

                        DragAndDrop.AcceptDrag();
                    }
                }
            }
            Event.current.Use();
        }
예제 #6
0
 private static void MigrateFromPre_1_4_1_0(ProjectSettings settings)
 {
     if (!CSFilterTools.IsValueMatchesAnyFilterOfKind("dummy.asmdef",
                                                      settings.projectCleanerSettings.pathIgnoresFilters, FilterKind.Extension))
     {
         ArrayUtility.Add(ref settings.projectCleanerSettings.pathIgnoresFilters,
                          FilterItem.Create(".asmdef", FilterKind.Extension));
     }
 }
예제 #7
0
        internal override void ProcessDrags()
        {
            if (currentEventType != EventType.DragUpdated && currentEventType != EventType.DragPerform)
            {
                return;
            }

            var paths            = DragAndDrop.paths;
            var objectReferences = DragAndDrop.objectReferences;

            if (paths != null && objectReferences != null && paths.Length > 0 && paths.Length == objectReferences.Length)
            {
                var atLeastOneFileAsset = objectReferences.Any(AssetDatabase.Contains);
                if (!atLeastOneFileAsset)
                {
                    return;
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                if (currentEventType == EventType.DragPerform)
                {
                    for (var i = 0; i < objectReferences.Length; i++)
                    {
                        paths[i] = CSPathTools.EnforceSlashes(AssetDatabase.GetAssetPath(objectReferences[i]));
                    }

                    var needToSave        = false;
                    var needToShowWarning = false;

                    foreach (var path in paths)
                    {
                        var added = CSFilterTools.TryAddNewItemToFilters(ref filters, FilterItem.Create(path, FilterKind.Path));
                        needToSave        |= added;
                        needToShowWarning |= !added;
                    }

                    if (needToSave)
                    {
                        SaveChanges();
                    }

                    if (needToShowWarning)
                    {
                        window.ShowNotification(new GUIContent("One or more of the dragged items already present in the list!"));
                    }

                    DragAndDrop.AcceptDrag();
                }
            }
            Event.current.Use();
        }
예제 #8
0
        private static void MigrateAllIgnores(ICollection <string> oldFilters, ref FilterItem[] newFilters, FilterKind filterKind)
        {
            if (oldFilters == null || oldFilters.Count == 0)
            {
                return;
            }

            var newFiltersList = new List <FilterItem>(oldFilters.Count);

            foreach (var oldFilter in oldFilters)
            {
                if (CSFilterTools.IsValueMatchesAnyFilter(oldFilter, newFilters))
                {
                    continue;
                }
                newFiltersList.Add(FilterItem.Create(oldFilter, filterKind));
            }

            ArrayUtility.AddRange(ref newFilters, newFiltersList.ToArray());
        }
예제 #9
0
        private static bool MigrateAllIgnores(string[] oldFilters, ref FilterItem[] newFilters, FilterKind filterKind)
        {
            if (oldFilters == null || oldFilters.Length == 0)
            {
                return(false);
            }

            var newFiltersList = new List <FilterItem>(oldFilters.Length);

            foreach (var oldFilter in oldFilters)
            {
                if (CSFilterTools.IsValueMatchesAnyFilter(oldFilter, newFilters))
                {
                    continue;
                }
                newFiltersList.Add(FilterItem.Create(oldFilter, filterKind));
            }

            ArrayUtility.AddRange(ref newFilters, newFiltersList.ToArray());

            return(true);
        }
예제 #10
0
        private static void ExcludeSubFoldersOfEmptyFolders(ref List <string> emptyFolders)
        {
            var emptyFoldersFiltered = new List <string>(emptyFolders.Count);

            for (var i = emptyFolders.Count - 1; i >= 0; i--)
            {
                var folder = emptyFolders[i];

                if (CSFilterTools.HasEnabledFilters(ProjectSettings.Cleaner.pathIncludesFilters))
                {
                    var emptyFolder = CSPathTools.GetProjectRelativePath(folder);
                    if (!CSFilterTools.IsValueMatchesAnyFilter(emptyFolder, ProjectSettings.Cleaner.pathIncludesFilters))
                    {
                        continue;
                    }
                }

                if (!CSArrayTools.IsItemContainsAnyStringFromArray(folder, emptyFoldersFiltered))
                {
                    emptyFoldersFiltered.Add(folder);
                }
            }
            emptyFolders = emptyFoldersFiltered;
        }
예제 #11
0
        internal static AssetInfo[] CollectTargetAssets()
        {
            var map = AssetsMap.GetUpdated();

            if (map == null)
            {
                Debug.LogError(Maintainer.LogPrefix + "Can't get updated assets map!");
                return(null);
            }

            EditorUtility.DisplayProgressBar(IssuesFinder.ModuleName, "Collecting input data...", 0);

            var supportedKinds = new List <AssetKind> {
                AssetKind.Regular, AssetKind.Settings
            };
            var assets = CSFilterTools.GetAssetInfosWithKinds(map.assets, supportedKinds);

            var result = new HashSet <AssetInfo>();

            try
            {
                var targetAssetTypes = new List <TypeFilter>();

                if (MaintainerSettings.Issues.lookInScenes)
                {
                    switch (MaintainerSettings.Issues.scenesSelection)
                    {
                    case IssuesFinderSettings.ScenesSelection.AllScenes:
                    {
                        targetAssetTypes.Add(new TypeFilter(CSReflectionTools.sceneAssetType));

                        break;
                    }

                    case IssuesFinderSettings.ScenesSelection.IncludedScenes:
                    {
                        if (MaintainerSettings.Issues.includeScenesInBuild)
                        {
                            var paths = CSSceneTools.GetScenesInBuild(!MaintainerSettings.Issues.includeOnlyEnabledScenesInBuild);
                            result.UnionWith(CSFilterTools.GetAssetInfosWithPaths(assets, paths));
                        }

                        var assetInfos = CSFilterTools.FilterAssetInfos(assets, MaintainerSettings.Issues.sceneIncludesFilters);
                        result.UnionWith(assetInfos);

                        break;
                    }

                    case IssuesFinderSettings.ScenesSelection.OpenedScenesOnly:
                    {
                        var paths = CSSceneTools.GetScenesSetup().Select(s => s.path).ToArray();
                        result.UnionWith(CSFilterTools.GetAssetInfosWithPaths(assets, paths));

                        break;
                    }

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                if (MaintainerSettings.Issues.lookInAssets)
                {
                    targetAssetTypes.Add(new TypeFilter(CSReflectionTools.scriptableObjectType, true));
                    targetAssetTypes.Add(new TypeFilter(null));
#if UNITY_2019_1_OR_NEWER
                    targetAssetTypes.Add(new TypeFilter(CSReflectionTools.shaderType));
#endif
                    if (MaintainerSettings.Issues.scanGameObjects)
                    {
                        targetAssetTypes.Add(new TypeFilter(CSReflectionTools.gameObjectType));
                    }
                }

                var filtered = CSFilterTools.FilterAssetInfos(
                    assets,
                    targetAssetTypes,
                    MaintainerSettings.Issues.pathIncludesFilters,
                    MaintainerSettings.Issues.pathIgnoresFilters
                    );

                result.UnionWith(filtered);

                if (MaintainerSettings.Issues.lookInProjectSettings)
                {
                    result.UnionWith(CSFilterTools.GetAssetInfosWithKind(assets, AssetKind.Settings));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            var resultArray = new AssetInfo[result.Count];
            result.CopyTo(resultArray);
            return(resultArray);
        }
예제 #12
0
        protected virtual void DrawAddItemSection()
        {
            EditorGUILayout.LabelField(GetAddNewLabel());
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Space(6);
                GUI.SetNextControlName("AddButton");

                var flag = currentEvent.isKey && Event.current.type == EventType.KeyDown && (currentEvent.keyCode == KeyCode.Return || currentEvent.keyCode == KeyCode.KeypadEnter);
                if (UIHelpers.IconButton(CSIcons.Plus, "Adds custom filter to the list.") || flag)
                {
                    if (string.IsNullOrEmpty(newItemText))
                    {
                        window.ShowNotification(new GUIContent("You can't add an empty filter!"));
                    }
                    else if (newItemText.IndexOf('*') != -1)
                    {
                        window.ShowNotification(new GUIContent("Masks are not supported!"));
                    }
                    else
                    {
                        if (newItemKind == FilterKind.Extension && !newItemText.StartsWith("."))
                        {
                            newItemText = "." + newItemText;
                        }

                        if (CheckNewItem(ref newItemText))
                        {
                            if (CSFilterTools.TryAddNewItemToFilters(ref filters, FilterItem.Create(newItemText, newItemKind, newItemIgnoreCase)))
                            {
                                SaveChanges();
                                newItemText = "";
                                GUI.FocusControl("AddButton");
                                didFocus = false;
                            }
                            else
                            {
                                window.ShowNotification(new GUIContent("This filter already exists in the list!"));
                            }
                        }
                    }
                }
                if (flag)
                {
                    currentEvent.Use();
                    currentEvent.Use();
                }

                newItemKind       = DrawFilterKindDropdown(newItemKind);
                newItemIgnoreCase = DrawFilterIgnoreCaseToggle(newItemIgnoreCase);
                GUILayout.Space(5);

                GUI.SetNextControlName("filtersTxt");
                newItemText = EditorGUILayout.TextField(newItemText);
                if (!didFocus)
                {
                    didFocus = true;
                    EditorGUI.FocusTextInControl("filtersTxt");
                }
            }
        }
예제 #13
0
        private static bool ScanProjectFiles(ICollection <CleanerRecord> results, bool showProgress = true)
        {
            currentPhase++;

            var ignoredScenes = new List <string>();

            if (ProjectSettings.Cleaner.ignoreScenesInBuild)
            {
                ignoredScenes.AddRange(CSSceneTools.GetScenesInBuild(!ProjectSettings.Cleaner.ignoreOnlyEnabledScenesInBuild));
            }

            foreach (var sceneFilter in ProjectSettings.Cleaner.sceneIgnoresFilters)
            {
                if (!sceneFilter.enabled)
                {
                    continue;
                }

                if (ignoredScenes.IndexOf(sceneFilter.value) == -1)
                {
                    ignoredScenes.Add(sceneFilter.value);
                }
            }

            CheckScenesForExistence(results, ignoredScenes);

            if (ignoredScenes.Count == 0)
            {
                if (!UserSettings.Cleaner.muteNoIgnoredScenesWarning)
                {
                    var dialogResult = EditorUtility.DisplayDialogComplex(
                        "No ignored scenes!",
                        "No scenes were added to the build settings or to the Filters > Scenes Ignores.\n" +
                        "All not ignored scenes are treated as unused if not referenced somewhere in other ignored assets.",
                        "Proceed anyway",
                        "Proceed and never show again", "Cancel");

                    if (dialogResult == 1)
                    {
                        UserSettings.Cleaner.muteNoIgnoredScenesWarning = true;
                        UserSettings.Save();
                    }
                    else if (dialogResult == 2)
                    {
                        return(false);
                    }
                }

                results.Add(CleanerWarningRecord.Create("No scenes added to the build settings or Filters > Scenes Ignores tab.\n" +
                                                        "Search may include all assets used in your game scenes!"));
            }

            var map = AssetsMap.GetUpdated();

            if (map == null)
            {
                results.Add(CleanerErrorRecord.Create("Can't get assets map!"));
                return(false);
            }

            EditorUtility.DisplayCancelableProgressBar(string.Format(ProgressCaption, currentPhase, phasesCount, 0, 0), "Analyzing Assets Map for references...", 0);

#if UNITY_2019_3_OR_NEWER
            BuildReportAnalyzer.Init();
#endif

            var allAssetsInProject = map.assets;
            var count = allAssetsInProject.Count;

#if !UNITY_2020_1_OR_NEWER
            var updateStep = Math.Max(count / ProjectSettings.UpdateProgressStep, 1);
#endif
            var referencedAssets = new HashSet <AssetInfo>();

            for (var i = 0; i < count; i++)
            {
                if (showProgress
#if !UNITY_2020_1_OR_NEWER
                    && i % updateStep == 0
#endif
                    && i != 0 && EditorUtility.DisplayCancelableProgressBar(
                        string.Format(ProgressCaption, currentPhase, phasesCount, i + 1, count), "Analyzing Assets Map for references...",
                        (float)(i + 1) / count))
                {
                    return(true);
                }

                var asset = allAssetsInProject[i];

                /*if (asset.Path.EndsWith("1.pdf"))
                 * {
                 *      Debug.Log(asset.Type);
                 *      if (asset.Type == CSReflectionTools.defaultAssetType)
                 *      {
                 *              var importer = AssetImporter.GetAtPath(asset.Path);
                 *              Debug.Log(importer);
                 *      }
                 * }*/

                if (asset.Kind != AssetKind.Regular)
                {
                    continue;
                }

                if (AssetInIgnores(asset, ignoredScenes))
                {
                    referencedAssets.Add(asset);
                    var references = asset.GetReferencesRecursive();
                    foreach (var reference in references)
                    {
                        referencedAssets.Add(reference);
                    }
                }

#if UNITY_2019_3_OR_NEWER
                if (BuildReportAnalyzer.IsFileInBuildReport(asset.GUID))
                {
                    referencedAssets.Add(asset);
                    var references = asset.GetReferencesRecursive();
                    foreach (var reference in references)
                    {
                        if (!referencedAssets.Contains(reference))
                        {
                            referencedAssets.Add(reference);
                        }
                    }
                }
#endif

                if (AssetInIgnoresSecondPass(asset, referencedAssets))
                {
                    referencedAssets.Add(asset);
                    var references = asset.GetReferencesRecursive();
                    foreach (var reference in references)
                    {
                        if (!referencedAssets.Contains(reference))
                        {
                            referencedAssets.Add(reference);
                        }
                    }
                }
            }

            var unreferencedAssets = new List <AssetInfo>(count);
            for (var i = 0; i < count; i++)
            {
                if (showProgress
#if !UNITY_2020_1_OR_NEWER
                    && i % updateStep == 0
#endif
                    && i != 0 && EditorUtility.DisplayCancelableProgressBar(
                        string.Format(ProgressCaption, currentPhase, phasesCount, i + 1, count), "Filtering out unreferenced assets...",
                        (float)(i + 1) / count))
                {
                    return(true);
                }

                var asset = allAssetsInProject[i];

                if (asset.Kind != AssetKind.Regular)
                {
                    continue;
                }

                if (CSFilterTools.HasEnabledFilters(ProjectSettings.Cleaner.pathIncludesFilters))
                {
                    if (!CSFilterTools.IsValueMatchesAnyFilter(asset.Path, ProjectSettings.Cleaner.pathIncludesFilters))
                    {
                        continue;
                    }
                }

                if (!referencedAssets.Contains(asset))
                {
                    if (unreferencedAssets.IndexOf(asset) == -1)
                    {
                        unreferencedAssets.Add(asset);
                    }
                }
            }

            count = unreferencedAssets.Count;

#if !UNITY_2020_1_OR_NEWER
            updateStep = Math.Max(count / ProjectSettings.UpdateProgressStep, 1);
#endif

            for (var i = count - 1; i > -1; i--)
            {
                if (showProgress
#if !UNITY_2020_1_OR_NEWER
                    && i % updateStep == 0
#endif
                    && i != 0)
                {
                    var index = count - i;
                    if (EditorUtility.DisplayCancelableProgressBar(
                            string.Format(ProgressCaption, currentPhase, phasesCount, index, count), "Populating results...",
                            (float)index / count))
                    {
                        return(true);
                    }
                }

                var unreferencedAsset = unreferencedAssets[i];
                results.Add(AssetRecord.Create(RecordType.UnreferencedAsset, unreferencedAsset));
            }

            return(false);
        }
예제 #14
0
        internal override void ProcessDrags()
        {
            if (currentEventType != EventType.DragUpdated && currentEventType != EventType.DragPerform)
            {
                return;
            }

            var objects = DragAndDrop.objectReferences;

            if (objects != null && objects.Length > 0)
            {
                var canDrop = false;

                for (var i = 0; i < objects.Length; i++)
                {
                    if (objects[i] is Component)
                    {
                        canDrop = true;
                        break;
                    }

                    var monoScript = objects[i] as MonoScript;
                    if (monoScript != null)
                    {
                        var type = monoScript.GetClass();
                        if (type.IsSubclassOf(CSReflectionTools.componentType))
                        {
                            canDrop = true;
                            break;
                        }
                    }
                }

                if (canDrop)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                    if (currentEventType == EventType.DragPerform)
                    {
                        var needToSave        = false;
                        var needToShowWarning = false;
                        var noComponent       = false;
                        var invalidComponent  = false;

                        for (var i = 0; i < objects.Length; i++)
                        {
                            var    component     = objects[i] as Component;
                            var    monoScript    = objects[i] as MonoScript;
                            string componentName = null;

                            if (component != null)
                            {
                                componentName = component.GetType().Name;
                            }
                            else if (monoScript != null)
                            {
                                var type = monoScript.GetClass();
                                if (type.IsSubclassOf(CSReflectionTools.componentType))
                                {
                                    componentName = type.Name;
                                }
                                else
                                {
                                    noComponent = true;
                                }
                            }
                            else
                            {
                                noComponent = true;
                            }

                            if (noComponent)
                            {
                                continue;
                            }

                            if (!string.IsNullOrEmpty(componentName) && componentName != "Object" && componentName != "Component" && componentName != "Behaviour")
                            {
                                var added = CSFilterTools.TryAddNewItemToFilters(ref filters, FilterItem.Create(componentName, FilterKind.Type));
                                needToSave        |= added;
                                needToShowWarning |= !added;
                            }
                            else
                            {
                                invalidComponent = true;
                            }
                        }

                        if (needToSave)
                        {
                            SaveChanges();
                        }

                        var warningText = "";

                        if (needToShowWarning)
                        {
                            warningText = "One or more of the dragged items already present in the list!";
                        }

                        if (noComponent)
                        {
                            if (!string.IsNullOrEmpty(warningText))
                            {
                                warningText += "\n";
                            }
                            warningText += "One or more of the dragged items are not the Components!";
                        }

                        if (invalidComponent)
                        {
                            if (!string.IsNullOrEmpty(warningText))
                            {
                                warningText += "\n";
                            }
                            warningText += "Can't detect valid name for one or more of the dragged items!";
                        }

                        if (!string.IsNullOrEmpty(warningText))
                        {
                            window.ShowNotification(new GUIContent(warningText));
                        }

                        DragAndDrop.AcceptDrag();
                    }
                }
            }
            Event.current.Use();
        }
예제 #15
0
        private static bool LookForReferences(FilterItem[] selectedAssets, List <ReferencesTreeElement> results)
        {
            var canceled = !CSSceneTools.SaveCurrentModifiedScenes(false);

            if (!canceled)
            {
                var map = AssetsMap.GetUpdated();
                if (map == null)
                {
                    return(true);
                }

                var count      = map.assets.Count;
                var updateStep = Math.Max(count / MaintainerSettings.UpdateProgressStep, 1);

                var root = new ReferencesTreeElement
                {
                    id    = results.Count,
                    name  = "root",
                    depth = -1
                };
                results.Add(root);

                for (var i = 0; i < count; i++)
                {
                    if (i % updateStep == 0 && EditorUtility.DisplayCancelableProgressBar(
                            string.Format(ProgressCaption, 1, PhasesCount),
                            string.Format(ProgressText, "Building references tree", i + 1, count),
                            (float)i / count))
                    {
                        canceled = true;
                        break;
                    }

                    var assetInfo = map.assets[i];

                    // excludes settings assets from the list depth 0 items
                    if (assetInfo.Kind == AssetKind.Settings)
                    {
                        continue;
                    }

                    // excludes all assets except selected ones from the list depth 0 items, if any was selected
                    if (selectedAssets != null)
                    {
                        if (!CSFilterTools.IsValueMatchesAnyFilter(assetInfo.Path, selectedAssets))
                        {
                            continue;
                        }
                    }

                    if (MaintainerSettings.References.pathIncludesFilters != null &&
                        MaintainerSettings.References.pathIncludesFilters.Length > 0)
                    {
                        // excludes all root assets except included ones
                        if (!CSFilterTools.IsValueMatchesAnyFilter(assetInfo.Path, MaintainerSettings.References.pathIncludesFilters))
                        {
                            continue;
                        }
                    }

                    // excludes ignored root asset
                    if (CSFilterTools.IsValueMatchesAnyFilter(assetInfo.Path, MaintainerSettings.References.pathIgnoresFilters))
                    {
                        continue;
                    }

                    var branchElements = new List <ReferencesTreeElement>();
                    TreeBuilder.BuildTreeBranch(assetInfo, 0, results.Count, branchElements);
                    results.AddRange(branchElements);
                }
            }

            if (!canceled)
            {
                canceled = ReferenceEntryFinder.FillReferenceEntries();
            }

            if (!canceled)
            {
                AssetsMap.Save();
            }

            if (canceled)
            {
                ReferencesTab.AutoShowExistsNotification = false;
                ReferencesTab.AutoSelectPath             = null;
            }

            return(canceled);
        }
        private static bool LookForAssetsReferences(FilterItem[] selectedAssets, List <ProjectReferenceItem> results)
        {
            var canceled = !CSSceneTools.SaveCurrentModifiedScenes(false);

            if (!canceled)
            {
                var map = AssetsMap.GetUpdated();
                if (map == null)
                {
                    return(true);
                }

                var count = map.assets.Count;

#if !UNITY_2020_1_OR_NEWER
                var updateStep = Math.Max(count / ProjectSettings.UpdateProgressStep, 1);
#endif
                var root = new ProjectReferenceItem
                {
                    id    = results.Count,
                    name  = "root",
                    depth = -1
                };
                results.Add(root);

                for (var i = 0; i < count; i++)
                {
                    if (
#if !UNITY_2020_1_OR_NEWER
                        i % updateStep == 0 &&
#endif
                        EditorUtility.DisplayCancelableProgressBar(
                            string.Format(ReferencesFinder.ProgressCaption, 1, ReferencesFinder.PhasesCount),
                            string.Format(ReferencesFinder.ProgressText, "Building references tree", i + 1, count),
                            (float)i / count))
                    {
                        canceled = true;
                        break;
                    }

                    var assetInfo = map.assets[i];

                    // excludes settings assets from the list depth 0 items
                    if (assetInfo.Kind == AssetKind.Settings)
                    {
                        continue;
                    }

                    // excludes all assets except selected ones from the list depth 0 items, if any was selected
                    if (selectedAssets != null)
                    {
                        if (!CSFilterTools.IsValueMatchesAnyFilter(assetInfo.Path, selectedAssets))
                        {
                            continue;
                        }
                    }

                    if (ProjectSettings.References.pathIncludesFilters != null &&
                        ProjectSettings.References.pathIncludesFilters.Length > 0)
                    {
                        // excludes all root assets except included ones
                        if (!CSFilterTools.IsValueMatchesAnyFilter(assetInfo.Path, ProjectSettings.References.pathIncludesFilters))
                        {
                            continue;
                        }
                    }

                    // excludes ignored root asset
                    if (CSFilterTools.IsValueMatchesAnyFilter(assetInfo.Path, ProjectSettings.References.pathIgnoresFilters))
                    {
                        continue;
                    }

                    var branchElements = new List <ProjectReferenceItem>();
                    ProjectScopeReferencesTreeBuilder.BuildTreeBranch(assetInfo, 0, results.Count, ConjunctionInfoList, branchElements);
                    results.AddRange(branchElements);
                }
            }

            if (!canceled)
            {
                canceled = ProjectEntryFinder.FillProjectScopeReferenceEntries(ConjunctionInfoList, TryAddEntryToMatchedConjunctions);
            }

            // TODO: remove this work-around when this bug will be fixed:
            // https://issuetracker.unity3d.com/issues/assets-used-in-components-of-a-nested-prefab-are-counted-as-direct-dependencies-of-all-higher-level-nested-prefabs
            for (var i = results.Count - 1; i >= 0; i--)
            {
                var result        = results[i];
                var resultEntries = result.referencingEntries;
                if (resultEntries == null || resultEntries.Length == 0)
                {
                    continue;
                }

                foreach (var referencingEntry in resultEntries)
                {
                    if (referencingEntry.Location == Location.NotFound && result.assetTypeName == "GameObject")
                    {
                        results.Remove(result);
                        break;
                    }
                }
            }

            if (!canceled)
            {
                AssetsMap.Save();
            }

            if (canceled)
            {
                ProjectReferencesTab.AutoSelectPath = null;
            }

            return(canceled);
        }
예제 #17
0
        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());
        }
예제 #18
0
        private static bool AssetInIgnores(AssetInfo assetInfo, List <string> ignoredScenes)
        {
            if (assetInfo.Type == CSReflectionTools.monoScriptType /* && !MaintainerSettings.Cleaner.findUnreferencedScripts*/)
            {
                return(true);
            }

            if (assetInfo.Type == CSReflectionTools.textAssetType)
            {
                return(true);
            }

            if (assetInfo.Type == CSReflectionTools.spriteAtlasType)
            {
                var atlas = AssetDatabase.LoadAssetAtPath <UnityEngine.U2D.SpriteAtlas>(assetInfo.Path);
                if (atlas != null)
                {
                    var so = new SerializedObject(atlas);

                    // source: SpriteAtlasInspector
                    var bindAsDefaultProperty = so.FindProperty("m_EditorData.bindAsDefault");
                    if (bindAsDefaultProperty != null)
                    {
                        if (bindAsDefaultProperty.boolValue)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        Debug.LogError(Maintainer.LogPrefix + "Can't parse UnityEngine.U2D.SpriteAtlas, please report to " + Maintainer.SupportEmail);
                    }
                }
                else
                {
                    Debug.LogWarning(Maintainer.LogPrefix + "Couldn't load SpriteAtlas: " + assetInfo.Path);
                }
            }

            if (assetInfo.Type == CSReflectionTools.assemblyDefinitionAssetType)
            {
                return(true);
            }

            if (assetInfo.Type == CSReflectionTools.defaultAssetType)
            {
                var importer = AssetImporter.GetAtPath(assetInfo.Path);
                if (importer is PluginImporter)
                {
                    return(true);
                }
                if (importer.ToString() == " (UnityEngine.DefaultImporter)")
                {
                    return(true);
                }
            }

            if (CSFilterTools.IsValueMatchesAnyFilter(assetInfo.Path, MaintainerSettings.Cleaner.MandatoryFilters))
            {
                return(true);
            }

            if (CSFilterTools.IsValueMatchesAnyFilter(assetInfo.Path, MaintainerSettings.Cleaner.pathIgnoresFilters))
            {
                return(true);
            }

            if (assetInfo.Type == CSReflectionTools.sceneAssetType && ignoredScenes.IndexOf(assetInfo.Path) != -1)
            {
                return(true);
            }

            foreach (var referencedAtInfo in assetInfo.referencedAtInfoList)
            {
                if (referencedAtInfo.assetInfo.SettingsKind != AssetSettingsKind.NotSettings && referencedAtInfo.assetInfo.SettingsKind != AssetSettingsKind.EditorBuildSettings)
                {
                    return(true);
                }

                if (referencedAtInfo.assetInfo.Kind == AssetKind.FromPackage)
                {
                    return(true);
                }
            }

            var assetBundleName = AssetDatabase.GetImplicitAssetBundleName(assetInfo.Path);

            if (!string.IsNullOrEmpty(assetBundleName))
            {
                return(true);
            }

            return(false);
        }
예제 #19
0
        private static bool FindEmptyFoldersRecursive(List <string> foundEmptyFolders, string root, bool showProgress, out bool canceledByUser)
        {
            var rootSubFolders = Directory.GetDirectories(root);

            var canceled        = false;
            var emptySubFolders = true;

            var count      = rootSubFolders.Length;
            var updateStep = Math.Max(count / MaintainerSettings.UpdateProgressStep, 1);

            for (var i = 0; i < count; i++)
            {
                var folder = CSPathTools.EnforceSlashes(rootSubFolders[i]);
                folderIndex++;

                if (showProgress && (i % updateStep == 0) && EditorUtility.DisplayCancelableProgressBar(
                        string.Format(ProgressCaption, currentPhase, phasesCount, folderIndex, foldersCount), "Scanning folders...",
                        (float)folderIndex / foldersCount))
                {
                    canceled = true;
                    break;
                }

                if (CSFilterTools.IsValueMatchesAnyFilter(folder.Replace('\\', '/'), MaintainerSettings.Cleaner.pathIgnoresFilters))
                {
                    emptySubFolders = false;
                    continue;
                }

                emptySubFolders &= FindEmptyFoldersRecursive(foundEmptyFolders, folder, showProgress, out canceled);
                if (canceled)
                {
                    break;
                }
            }

            if (canceled)
            {
                canceledByUser = true;
                return(false);
            }

            var rootFolderHasFiles = true;
            var filesInRootFolder  = Directory.GetFiles(root);

            foreach (var file in filesInRootFolder)
            {
                if (file.EndsWith(".meta", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                rootFolderHasFiles = false;
                break;
            }

            var rootFolderEmpty = emptySubFolders && rootFolderHasFiles;

            if (rootFolderEmpty)
            {
                foundEmptyFolders.Add(root);
            }

            canceledByUser = false;
            return(rootFolderEmpty);
        }
예제 #20
0
        private void DrawMoreButton(AssetRecord assetRecord)
        {
            if (UIHelpers.RecordButton(assetRecord, "Shows menu with additional actions for this record.", CSIcons.More))
            {
                var menu = new GenericMenu();
                if (!string.IsNullOrEmpty(assetRecord.path))
                {
                    menu.AddItem(new GUIContent("Ignore/Full Path"), false, () =>
                    {
                        if (!CSFilterTools.IsValueMatchesAnyFilter(assetRecord.assetDatabasePath, MaintainerSettings.Cleaner.pathIgnoresFilters))
                        {
                            var newFilter = FilterItem.Create(assetRecord.assetDatabasePath, FilterKind.Path);
                            ArrayUtility.Add(ref MaintainerSettings.Cleaner.pathIgnoresFilters, newFilter);

                            MaintainerWindow.ShowNotification("Ignore added: " + assetRecord.assetDatabasePath);
                            CleanerFiltersWindow.Refresh();

                            if (MaintainerSettings.Cleaner.rescanAfterContextIgnore)
                            {
                                StartSearch();
                            }
                        }
                        else
                        {
                            MaintainerWindow.ShowNotification("Already added to the ignores!");
                        }
                    });

                    var dir = Directory.GetParent(assetRecord.assetDatabasePath);
                    if (!CSPathTools.IsAssetsRootPath(dir.FullName))
                    {
                        menu.AddItem(new GUIContent("Ignore/Parent Folder"), false, () =>
                        {
                            var dirPath = CSPathTools.EnforceSlashes(dir.ToString());

                            if (!CSFilterTools.IsValueMatchesAnyFilter(dirPath, MaintainerSettings.Cleaner.pathIgnoresFilters))
                            {
                                var newFilter = FilterItem.Create(dirPath, FilterKind.Directory);
                                ArrayUtility.Add(ref MaintainerSettings.Cleaner.pathIgnoresFilters, newFilter);

                                MaintainerWindow.ShowNotification("Ignore added: " + dirPath);
                                CleanerFiltersWindow.Refresh();

                                if (MaintainerSettings.Cleaner.rescanAfterContextIgnore)
                                {
                                    StartSearch();
                                }
                            }
                            else
                            {
                                MaintainerWindow.ShowNotification("Already added to the ignores!");
                            }
                        });
                    }

                    var extension = Path.GetExtension(assetRecord.path);
                    if (!string.IsNullOrEmpty(extension))
                    {
                        menu.AddItem(new GUIContent("Ignore/\"" + extension + "\" Extension"), false, () =>
                        {
                            if (!CSFilterTools.IsValueMatchesAnyFilterOfKind(extension, MaintainerSettings.Cleaner.pathIgnoresFilters, FilterKind.Extension))
                            {
                                var newFilter = FilterItem.Create(extension, FilterKind.Extension, true);
                                ArrayUtility.Add(ref MaintainerSettings.Cleaner.pathIgnoresFilters, newFilter);

                                MaintainerWindow.ShowNotification("Ignore added: " + extension);
                                CleanerFiltersWindow.Refresh();

                                if (MaintainerSettings.Cleaner.rescanAfterContextIgnore)
                                {
                                    StartSearch();
                                }
                            }
                            else
                            {
                                MaintainerWindow.ShowNotification("Already added to the ignores!");
                            }
                        });
                    }
                }
                menu.ShowAsContext();
            }
        }
예제 #21
0
        private static MaintainerSettings LoadOrCreate()
        {
            MaintainerSettings settings;

            if (!File.Exists(Path))
            {
                settings = CreateNewSettingsFile();
            }
            else
            {
                settings = LoadInstance();

                if (settings == null)
                {
                    CSFileTools.DeleteFile(Path);
                    settings = CreateNewSettingsFile();
                }

                if (settings.version != Maintainer.Version)
                {
                    if (string.IsNullOrEmpty(settings.version))
                    {
                        MigrateAllIgnores(settings.issuesFinderSettings.pathIgnores, ref settings.issuesFinderSettings.pathIgnoresFilters, FilterKind.Path);
                        settings.issuesFinderSettings.pathIgnores = null;

                        MigrateAllIgnores(settings.issuesFinderSettings.componentIgnores, ref settings.issuesFinderSettings.componentIgnoresFilters, FilterKind.Type);
                        settings.issuesFinderSettings.componentIgnores = null;

                        MigrateAllIgnores(settings.issuesFinderSettings.pathIncludes, ref settings.issuesFinderSettings.pathIncludesFilters, FilterKind.Path);
                        settings.issuesFinderSettings.pathIncludes = null;

                        MigrateAllIgnores(settings.issuesFinderSettings.sceneIncludes, ref settings.issuesFinderSettings.sceneIncludesFilters, FilterKind.Path);
                        settings.issuesFinderSettings.sceneIncludes = null;

                        MigrateAllIgnores(settings.projectCleanerSettings.pathIgnores, ref settings.projectCleanerSettings.pathIgnoresFilters, FilterKind.Path);
                        settings.projectCleanerSettings.pathIgnores = null;

                        MigrateAllIgnores(settings.projectCleanerSettings.sceneIgnores, ref settings.projectCleanerSettings.sceneIgnoresFilters, FilterKind.Path);
                        settings.projectCleanerSettings.sceneIgnores = null;

                        settings.projectCleanerSettings.AddDefaultFilters();
                    }

                    if (new Version(settings.version) < new Version("1.4.1.0"))
                    {
                        if (!CSFilterTools.IsValueMatchesAnyFilterOfKind("dummy.asmdef", settings.projectCleanerSettings.pathIgnoresFilters, FilterKind.Extension))
                        {
                            ArrayUtility.Add(ref settings.projectCleanerSettings.pathIgnoresFilters, FilterItem.Create(".asmdef", FilterKind.Extension));
                        }
                    }

                    if (new Version(settings.version) < new Version("1.5.1"))
                    {
                        if (settings.projectCleanerSettings.pathIgnoresFilters != null &&
                            settings.projectCleanerSettings.pathIgnoresFilters.Length > 0)
                        {
                            var defaultFilters   = settings.projectCleanerSettings.GetDefaultFilters();
                            var mandatoryFilters = settings.projectCleanerSettings.MandatoryFilters;

                            var modificationsLog = new StringBuilder();

                            for (var i = settings.projectCleanerSettings.pathIgnoresFilters.Length - 1; i >= 0; i--)
                            {
                                var pathIgnoresFilter = settings.projectCleanerSettings.pathIgnoresFilters[i];
                                if (pathIgnoresFilter.ignoreCase)
                                {
                                    continue;
                                }

                                var isMandatory = false;

                                if (CSFilterTools.IsValueMatchesAnyFilterOfKind(pathIgnoresFilter.value, mandatoryFilters, pathIgnoresFilter.kind))
                                {
                                    isMandatory = true;
                                }
                                else
                                {
                                    switch (pathIgnoresFilter.kind)
                                    {
                                    case FilterKind.Extension:
                                        var extension = pathIgnoresFilter.value.ToLowerInvariant();
                                        if (extension == ".dll" ||
                                            extension == ".asmdef" ||
                                            extension == ".mdb" ||
                                            extension == ".xml" ||
                                            extension == ".rsp")
                                        {
                                            isMandatory = true;
                                        }
                                        break;

                                    case FilterKind.FileName:
                                        var value = pathIgnoresFilter.value.ToLowerInvariant();
                                        if (value == "readme" ||
                                            value == "manual")
                                        {
                                            isMandatory = true;
                                        }
                                        break;
                                    }
                                }

                                if (isMandatory)
                                {
                                    modificationsLog.Append("Removing Project Cleaner filter '")
                                    .Append(pathIgnoresFilter.value)
                                    .AppendLine("': built-in mandatory filter covers it now.");
                                    ArrayUtility.RemoveAt(ref settings.projectCleanerSettings.pathIgnoresFilters, i);
                                    continue;
                                }

                                if (CSFilterTools.IsValueMatchesAnyFilterOfKind(pathIgnoresFilter.value, defaultFilters, pathIgnoresFilter.kind))
                                {
                                    modificationsLog.Append("Changing default Project Cleaner filter '")
                                    .Append(pathIgnoresFilter.value)
                                    .AppendLine("': ignore case setting to 'true' for better accuracy.");
                                    pathIgnoresFilter.ignoreCase = true;
                                }
                            }

                            if (modificationsLog.Length > 0)
                            {
                                modificationsLog.Insert(0, "Maintainer settings updated, read below for details\n");
                                Debug.Log(Maintainer.LogPrefix + modificationsLog);
                            }
                        }
                    }

                    SearchResultsStorage.Clear();
                    //AssetsMap.Delete();
                }
            }

            settings.hideFlags = HideFlags.HideAndDontSave;
            settings.version   = Maintainer.Version;

            return(settings);
        }
예제 #22
0
        private static void MigrateFromPre_1_5_1(ProjectSettings settings)
        {
            if (settings.projectCleanerSettings.pathIgnoresFilters != null &&
                settings.projectCleanerSettings.pathIgnoresFilters.Length > 0)
            {
                var defaultFilters   = ProjectCleanerSettings.GetDefaultFilters();
                var mandatoryFilters = settings.projectCleanerSettings.MandatoryFilters;

                var modificationsLog = new StringBuilder();

                for (var i = settings.projectCleanerSettings.pathIgnoresFilters.Length - 1; i >= 0; i--)
                {
                    var pathIgnoresFilter = settings.projectCleanerSettings.pathIgnoresFilters[i];
                    if (pathIgnoresFilter.ignoreCase)
                    {
                        continue;
                    }

                    var isMandatory = false;

                    if (CSFilterTools.IsValueMatchesAnyFilterOfKind(pathIgnoresFilter.value, mandatoryFilters,
                                                                    pathIgnoresFilter.kind))
                    {
                        isMandatory = true;
                    }
                    else
                    {
                        switch (pathIgnoresFilter.kind)
                        {
                        case FilterKind.Extension:
                            var extension = pathIgnoresFilter.value.ToLowerInvariant();
                            if (extension == ".dll" ||
                                extension == ".asmdef" ||
                                extension == ".mdb" ||
                                extension == ".xml" ||
                                extension == ".rsp")
                            {
                                isMandatory = true;
                            }

                            break;

                        case FilterKind.FileName:
                            var value = pathIgnoresFilter.value.ToLowerInvariant();
                            if (value == "readme" ||
                                value == "manual")
                            {
                                isMandatory = true;
                            }

                            break;
                        }
                    }

                    if (isMandatory)
                    {
                        modificationsLog.Append("Removing Project Cleaner filter '")
                        .Append(pathIgnoresFilter.value)
                        .AppendLine("': built-in mandatory filter covers it now.");
                        ArrayUtility.RemoveAt(ref settings.projectCleanerSettings.pathIgnoresFilters, i);
                        continue;
                    }

                    if (CSFilterTools.IsValueMatchesAnyFilterOfKind(pathIgnoresFilter.value, defaultFilters,
                                                                    pathIgnoresFilter.kind))
                    {
                        modificationsLog.Append("Changing default Project Cleaner filter '")
                        .Append(pathIgnoresFilter.value)
                        .AppendLine("': ignore case setting to 'true' for better accuracy.");
                        pathIgnoresFilter.ignoreCase = true;
                    }
                }

                if (modificationsLog.Length > 0)
                {
                    modificationsLog.Insert(0, "Maintainer settings updated, read below for details\n");
                    Debug.Log(Maintainer.LogPrefix + modificationsLog);
                }
            }
        }
예제 #23
0
        /////////////////////////////////////////////////////////////////////////
        // Game Object's Components Processing
        /////////////////////////////////////////////////////////////////////////

        public static void ProcessComponent(Component component, int orderIndex)
        {
#if !UNITY_2019_1_OR_NEWER
            if (missingComponentDetector.CheckAndRecordNullComponent(component))
            {
                return;
            }
#else
            if (component == null)
            {
                return;
            }
#endif

            if ((component.hideFlags & HideFlags.HideInInspector) != 0)
            {
                return;
            }

            if (!MaintainerSettings.Issues.touchDisabledComponents)
            {
                if (EditorUtility.GetObjectEnabled(component) == 0)
                {
                    return;
                }
            }

            var componentType = component.GetType();
            var componentName = componentType.Name;

            if (MaintainerSettings.Issues.componentIgnoresFilters != null &&
                MaintainerSettings.Issues.componentIgnoresFilters.Length > 0)
            {
                if (CSFilterTools.IsValueMatchesAnyFilterOfKind(componentName, MaintainerSettings.Issues.componentIgnoresFilters, FilterKind.Type))
                {
                    return;
                }
            }

            duplicateComponentDetector.ProcessComponent(component, componentType);

            var shouldCheckPropertiesForDuplicate = duplicateComponentDetector.IsPropertiesHashCalculationRequired();
            if (shouldCheckPropertiesForDuplicate)
            {
                // skipping duplicate search for non-standard components with invisible properties
                var baseType = componentType.BaseType;
                if (baseType != null)
                {
                    if (baseType.Name == "MegaModifier")
                    {
                        shouldCheckPropertiesForDuplicate = false;
                        duplicateComponentDetector.SkipComponent();
                    }
                }
            }

            var shouldTraverseProperties = missingReferenceDetector.Enabled || shouldCheckPropertiesForDuplicate;
            if (shouldTraverseProperties)
            {
                var initialInfo = new SerializedObjectTraverseInfo(component);

                CSTraverseTools.TraverseObjectProperties(initialInfo, (info, property) =>
                {
                    if (property.type == "UnityEvent")
                    {
                        missingReferenceDetector.TryDetectUnityEventIssues(currentLocation, currentAsset.Path,
                                                                           currentGameObject, componentType, componentName, orderIndex, property);

                        info.skipCurrentTree = true;
                        return;
                    }

                    missingReferenceDetector.TryDetectIssue(currentLocation, currentAsset.Path, currentGameObject, componentType, componentName, orderIndex, property);

                    if (shouldCheckPropertiesForDuplicate)
                    {
                        duplicateComponentDetector.ProcessProperty(property);
                    }
                });
            }

            if (shouldCheckPropertiesForDuplicate)
            {
                duplicateComponentDetector.TryDetectIssue(currentLocation, currentAsset.Path, currentGameObject, componentType, componentName, orderIndex);
            }

            if (component is Terrain)
            {
                inconsistentTerrainDataDetector.ProcessTerrainComponent((Terrain)component, componentType, componentName, orderIndex);
            }
            else if (component is TerrainCollider)
            {
                inconsistentTerrainDataDetector.ProcessTerrainColliderComponent((TerrainCollider)component);
            }
            //Debug.Log("ProcessComponent: " + target.name + ":" + component);
        }
예제 #24
0
        private void DrawMoreButton(AssetIssueRecord record)
        {
            if (!UIHelpers.RecordButton(record, "Shows menu with additional actions for this record.", CSIcons.More))
            {
                return;
            }

            var menu = new GenericMenu();

            if (!string.IsNullOrEmpty(record.Path))
            {
                menu.AddItem(new GUIContent("Ignore/Full Path"), false, () =>
                {
                    if (!CSFilterTools.IsValueMatchesAnyFilter(record.Path, ProjectSettings.Issues.pathIgnoresFilters))
                    {
                        var newFilter = FilterItem.Create(record.Path, FilterKind.Path);
                        ArrayUtility.Add(ref ProjectSettings.Issues.pathIgnoresFilters, newFilter);

                        ApplyNewIgnoreFilter(newFilter);

                        MaintainerWindow.ShowNotification("Ignore added: " + record.Path);
                        CleanerFiltersWindow.Refresh();
                    }
                    else
                    {
                        MaintainerWindow.ShowNotification("Already added to the ignores!");
                    }
                });

                var dir = Directory.GetParent(record.Path);
                if (!CSPathTools.IsAssetsRootPath(dir.FullName))
                {
                    menu.AddItem(new GUIContent("Ignore/Parent Folder"), false, () =>
                    {
                        var dirPath = CSPathTools.EnforceSlashes(dir.ToString());

                        if (!CSFilterTools.IsValueMatchesAnyFilter(dirPath, ProjectSettings.Issues.pathIgnoresFilters))
                        {
                            var newFilter = FilterItem.Create(dirPath, FilterKind.Directory);
                            ArrayUtility.Add(ref ProjectSettings.Issues.pathIgnoresFilters, newFilter);

                            ApplyNewIgnoreFilter(newFilter);

                            MaintainerWindow.ShowNotification("Ignore added: " + dirPath);
                            CleanerFiltersWindow.Refresh();
                        }
                        else
                        {
                            MaintainerWindow.ShowNotification("Already added to the ignores!");
                        }
                    });
                }
            }

            var objectIssue = record as GameObjectIssueRecord;

            if (objectIssue != null)
            {
                if (!string.IsNullOrEmpty(objectIssue.componentName))
                {
                    menu.AddItem(new GUIContent("Ignore/\"" + objectIssue.componentName + "\" Component"), false, () =>
                    {
                        if (!CSFilterTools.IsValueMatchesAnyFilter(objectIssue.componentName, ProjectSettings.Issues.componentIgnoresFilters))
                        {
                            var newFilter = FilterItem.Create(objectIssue.componentName, FilterKind.Type);
                            ArrayUtility.Add(ref ProjectSettings.Issues.componentIgnoresFilters, newFilter);

                            ApplyNewIgnoreFilter(newFilter);

                            MaintainerWindow.ShowNotification("Ignore added: " + objectIssue.componentName);
                            CleanerFiltersWindow.Refresh();
                        }
                        else
                        {
                            MaintainerWindow.ShowNotification("Already added to the ignores!");
                        }
                    });
                }
            }


            menu.ShowAsContext();
        }