Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        private void ActualizePath()
        {
            if (Kind == AssetKind.FromPackage)
            {
                return;
            }

            var actualPath = CSPathTools.EnforceSlashes(AssetDatabase.GUIDToAssetPath(GUID));

            if (!string.IsNullOrEmpty(actualPath) && actualPath != Path)
            {
                fileInfo     = new FileInfo(actualPath);
                metaFileInfo = new FileInfo(actualPath + ".meta");
                Path         = actualPath;
            }
        }
Ejemplo n.º 3
0
        internal static string[] GetSelectedAssets(int[] instanceIDs)
        {
            var paths = new List <string>(instanceIDs.Length);

            foreach (var id in instanceIDs)
            {
                if (AssetDatabase.IsSubAsset(id))
                {
                    continue;
                }
                var path = AssetDatabase.GetAssetPath(id);
                path = CSPathTools.EnforceSlashes(path);
                if (!File.Exists(path) && !Directory.Exists(path))
                {
                    continue;
                }
                paths.Add(path);
            }

            return(paths.ToArray());
        }
Ejemplo n.º 4
0
        private IEnumerable <string> GetAssetsReferencedFromAssemblyDefinitionReference(string assetPath)
        {
            var result = new List <string>();

            var asset = AssetDatabase.LoadAssetAtPath <UnityEditorInternal.AssemblyDefinitionReferenceAsset>(assetPath);
            var data  = JsonUtility.FromJson <AssemblyDefinitionReferenceData>(asset.text);

            if (!string.IsNullOrEmpty(data.reference))
            {
                var assemblyDefinitionPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyReference(data.reference);
                if (!string.IsNullOrEmpty(assemblyDefinitionPath))
                {
                    assemblyDefinitionPath = CSPathTools.EnforceSlashes(assemblyDefinitionPath);
                    result.Add(assemblyDefinitionPath);
                }
            }

            data.reference = null;

            return(result);
        }
Ejemplo n.º 5
0
        private static void FillSettingsAssetDependencies(ref HashSet <string> dependenciesGUIDs, string assetPath, AssetSettingsKind settingsKind)
        {
            if (settingsKind == AssetSettingsKind.EditorBuildSettings)
            {
                var scenesInBuildGUIDs = CSSceneTools.GetScenesInBuildGUIDs(true);
                if (scenesInBuildGUIDs != null)
                {
                    dependenciesGUIDs.UnionWith(scenesInBuildGUIDs);
                }
            }
            else
            {
                var settingsAsset = AssetDatabase.LoadAllAssetsAtPath(assetPath);
                if (settingsAsset != null && settingsAsset.Length > 0)
                {
                    var settingsAssetSerialized = new SerializedObject(settingsAsset[0]);

                    var sp = settingsAssetSerialized.GetIterator();
                    while (sp.Next(true))
                    {
                        if (sp.propertyType == SerializedPropertyType.ObjectReference)
                        {
                            var instanceId = sp.objectReferenceInstanceIDValue;
                            if (instanceId != 0)
                            {
                                var path = CSPathTools.EnforceSlashes(AssetDatabase.GetAssetPath(instanceId));
                                if (!string.IsNullOrEmpty(path) && path.StartsWith("Assets"))
                                {
                                    var guid = AssetDatabase.AssetPathToGUID(path);
                                    if (!string.IsNullOrEmpty(guid))
                                    {
                                        dependenciesGUIDs.Add(guid);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static string[] GetAssetsReferencedInPlayerSettingsAsset(string assetPath, AssetSettingsKind settingsKind)
        {
            var referencedAssets = new List <string>();

            if (settingsKind == AssetSettingsKind.EditorBuildSettings)
            {
                referencedAssets.AddRange(CSSceneTools.GetScenesInBuild(true));
            }
            else
            {
                var settingsAsset = AssetDatabase.LoadAllAssetsAtPath(assetPath);
                if (settingsAsset != null && settingsAsset.Length > 0)
                {
                    var settingsAssetSerialized = new SerializedObject(settingsAsset[0]);

                    var sp = settingsAssetSerialized.GetIterator();
                    while (sp.Next(true))
                    {
                        if (sp.propertyType == SerializedPropertyType.ObjectReference)
                        {
                            var instanceId = sp.objectReferenceInstanceIDValue;
                            if (instanceId != 0)
                            {
                                var path = CSPathTools.EnforceSlashes(AssetDatabase.GetAssetPath(instanceId));
                                if (!string.IsNullOrEmpty(path) && path.StartsWith("Assets"))
                                {
                                    if (referencedAssets.IndexOf(path) == -1)
                                    {
                                        referencedAssets.Add(path);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(referencedAssets.ToArray());
        }
Ejemplo n.º 7
0
        private List <string> GetAssetsReferencedFromAssemblyDefinition(string assetPath)
        {
            var result = new List <string>();

            var asset = AssetDatabase.LoadAssetAtPath <UnityEditorInternal.AssemblyDefinitionAsset>(assetPath);
            var data  = JsonUtility.FromJson <AssemblyDefinitionData>(asset.text);

            if (data.references != null && data.references.Length > 0)
            {
                foreach (var reference in data.references)
                {
                    var assemblyDefinitionFilePathFromAssemblyName = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyName(reference);
                    if (!string.IsNullOrEmpty(assemblyDefinitionFilePathFromAssemblyName))
                    {
                        assemblyDefinitionFilePathFromAssemblyName = CSPathTools.EnforceSlashes(assemblyDefinitionFilePathFromAssemblyName);
                        result.Add(assemblyDefinitionFilePathFromAssemblyName);
                    }
                }
            }

            data.references = null;

            return(result);
        }
Ejemplo n.º 8
0
        private static bool UpdateMap(AssetsMap map)
        {
            // ----------------------------------------
            // getting all valid assets within project
            // ----------------------------------------
            if (EditorUtility.DisplayCancelableProgressBar("Updating Assets Map, phase 1 of 4", "Getting all valid assets...", 0))
            {
                Debug.LogError(Maintainer.LogPrefix + "Assets Map update was canceled by user.");
                return(false);
            }

            var allAssetPaths  = AssetDatabase.GetAllAssetPaths();
            var validNewAssets = new List <RawAssetInfo>(allAssetPaths.Length);

            foreach (var assetPath in allAssetPaths)
            {
                /*if (assetPath.Contains(@"ScriptableObjectScriptWithMissingScript"))
                 * {
                 *      Debug.Log(assetPath);
                 * }*/

                var kind = CSEditorTools.GetAssetKind(assetPath);
                if (kind == AssetKind.Unsupported)
                {
                    continue;
                }

                if (!File.Exists(assetPath))
                {
                    continue;
                }
                if (AssetDatabase.IsValidFolder(assetPath))
                {
                    continue;
                }

                var guid    = AssetDatabase.AssetPathToGUID(assetPath);
                var rawInfo = new RawAssetInfo
                {
                    path = CSPathTools.EnforceSlashes(assetPath),
                    guid = guid,
                    kind = kind,
                };

                validNewAssets.Add(rawInfo);
            }

            // -----------------------------
            // checking existing map assets
            // -----------------------------

            if (EditorUtility.DisplayCancelableProgressBar("Updating Assets Map, phase 2 of 4", "Checking existing assets in map...", 0))
            {
                Debug.LogError(Maintainer.LogPrefix + "Assets Map update was canceled by user.");
                return(false);
            }

            var count = map.assets.Count;

#if !UNITY_2020_1_OR_NEWER
            var updateStep = Math.Max(count / ProjectSettings.UpdateProgressStep, 1);
#endif
            for (var i = count - 1; i > -1; i--)
            {
#if !UNITY_2020_1_OR_NEWER
                if (i % updateStep == 0 && i != 0)
#endif
                {
                    var index = count - i;
                    if (EditorUtility.DisplayCancelableProgressBar("Updating Assets Map, phase 2 of 4", "Checking existing assets in map..." + index + "/" + count, (float)index / count))
                    {
                        EditorUtility.ClearProgressBar();
                        Debug.LogError(Maintainer.LogPrefix + "Assets Map update was canceled by user.");
                        return(false);
                    }
                }

                var assetInMap = map.assets[i];
                if (assetInMap.Exists())
                {
                    validNewAssets.RemoveAll(a => a.guid == assetInMap.GUID);
                    assetInMap.UpdateIfNeeded();
                }
                else
                {
                    assetInMap.Clean();
                    map.assets.RemoveAt(i);
                }
            }

            // ------------------------
            // dealing with new assets
            // ------------------------

            if (EditorUtility.DisplayCancelableProgressBar("Updating Assets Map, phase 3 of 4", "Looking for new assets...", 0))
            {
                Debug.LogError(Maintainer.LogPrefix + "Assets Map update was canceled by user.");
                return(false);
            }

            count = validNewAssets.Count;
#if !UNITY_2020_1_OR_NEWER
            updateStep = Math.Max(count / ProjectSettings.UpdateProgressStep, 1);
#endif
            for (var i = 0; i < count; i++)
            {
#if !UNITY_2020_1_OR_NEWER
                if (i % updateStep == 0 && i != 0)
#endif
                {
                    if (EditorUtility.DisplayCancelableProgressBar("Updating Assets Map, phase 3 of 4",
                                                                   "Looking for new assets..." + (i + 1) + "/" + count, (float)i / count))
                    {
                        Debug.LogError(Maintainer.LogPrefix + "Assets Map update was canceled by user.");
                        return(false);
                    }
                }

                var rawAssetInfo     = validNewAssets[i];
                var rawAssetInfoPath = rawAssetInfo.path;

                var type = AssetDatabase.GetMainAssetTypeAtPath(rawAssetInfoPath);
                if (type == null)
                {
                    var loadedAsset = AssetDatabase.LoadMainAssetAtPath(rawAssetInfoPath);
                    if (loadedAsset == null)
                    {
                        if (rawAssetInfo.kind != AssetKind.FromPackage)
                        {
                            if (!CSAssetTools.IsAssetScriptableObjectWithMissingScript(rawAssetInfoPath))
                            {
                                Debug.LogWarning(Maintainer.LogPrefix + "Can't retrieve type of the asset:\n" +
                                                 rawAssetInfoPath);
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        type = loadedAsset.GetType();
                    }
                }

                var settingsKind = rawAssetInfo.kind == AssetKind.Settings ? GetSettingsKind(rawAssetInfoPath) : AssetSettingsKind.NotSettings;

                var asset = AssetInfo.Create(rawAssetInfo, type, settingsKind);
                map.assets.Add(asset);
            }

            if (EditorUtility.DisplayCancelableProgressBar("Updating Assets Map, phase 4 of 4", "Generating links...", 0))
            {
                Debug.LogError(Maintainer.LogPrefix + "Assets Map update was canceled by user.");
                return(false);
            }

            count = map.assets.Count;

#if !UNITY_2020_1_OR_NEWER
            updateStep = Math.Max(count / ProjectSettings.UpdateProgressStep, 1);
#endif
            for (var i = 0; i < count; i++)
            {
#if !UNITY_2020_1_OR_NEWER
                if (i % updateStep == 0 && i != 0)
#endif
                {
                    if (EditorUtility.DisplayCancelableProgressBar("Updating Assets Map, phase 4 of 4", "Generating links..." + (i + 1) + "/" + count, (float)i / count))
                    {
                        Debug.LogError(Maintainer.LogPrefix + "Assets Map update was canceled by user.");
                        return(false);
                    }
                }

                var asset = map.assets[i];

                if (!asset.needToRebuildReferences)
                {
                    continue;
                }

                var dependencies   = asset.dependenciesGUIDs;
                var referenceInfos = new List <AssetReferenceInfo>(asset.assetReferencesInfo);

                foreach (var mapAsset in map.assets)
                {
                    var referencedAtInfos = new List <ReferencedAtAssetInfo>(mapAsset.referencedAtInfoList);

                    foreach (var dependency in dependencies)
                    {
                        if (mapAsset.GUID != dependency)
                        {
                            continue;
                        }
                        if (mapAsset.Type == asset.Type && asset.Type == CSReflectionTools.fontType)
                        {
                            continue;
                        }

                        var referencedAtInfo = new ReferencedAtAssetInfo()
                        {
                            assetInfo = asset
                        };
                        referencedAtInfos.Add(referencedAtInfo);

                        var referenceInfo = new AssetReferenceInfo()
                        {
                            assetInfo = mapAsset
                        };
                        referenceInfos.Add(referenceInfo);
                    }

                    mapAsset.referencedAtInfoList = referencedAtInfos.ToArray();
                }

                asset.assetReferencesInfo     = referenceInfos.ToArray();
                asset.needToRebuildReferences = false;
            }

            /*Debug.Log("Total assets in map: " + map.assets.Count);
             * foreach (var mapAsset in map.assets)
             * {
             *      //if (!(mapAsset.path.Contains("frag_ab") || mapAsset.path.Contains("frag_ac"))) continue;
             *      if (!mapAsset.Path.Contains("NewAssembly")) continue;
             *
             *      Debug.Log("==================================================\n" + mapAsset.Path + "\n" + mapAsset.Path);
             *      Debug.Log("[REFERENCED BY]");
             *      foreach (var reference in mapAsset.referencedAtInfoList)
             *      {
             *              Debug.Log(reference.assetInfo.Path);
             *      }
             *
             *      Debug.Log("[REFERENCES]");
             *      foreach (var reference in mapAsset.assetReferencesInfo)
             *      {
             *              Debug.Log(reference.assetInfo.Path);
             *      }
             * }*/

            return(true);
        }
Ejemplo n.º 9
0
 protected override bool CheckNewItem(ref string newItem)
 {
     newItem = CSPathTools.EnforceSlashes(newItem);
     return(true);
 }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        protected override bool PerformClean()
        {
            bool result;

            if (ProjectSettings.Cleaner.useTrashBin)
            {
                result = AssetDatabase.MoveAssetToTrash(assetDatabasePath);
            }
            else
            {
                switch (type)
                {
                case RecordType.EmptyFolder:
                {
                    if (Directory.Exists(path))
                    {
                        Directory.Delete(path, true);
                    }
                    break;
                }

                case RecordType.UnreferencedAsset:
                {
                    CSFileTools.DeleteFile(path);
                    break;
                }

                case RecordType.Error:
                    break;

                case RecordType.Other:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                var metaPath = path + ".meta";
                CSFileTools.DeleteFile(metaPath);
                result = !(Directory.Exists(path) || File.Exists(path));
            }

            if (!result)
            {
                Debug.LogWarning(Maintainer.LogPrefix + ProjectCleaner.ModuleName + " can't clean asset: " + beautyPath);
            }
            else
            {
                var directory = CSPathTools.EnforceSlashes(Path.GetDirectoryName(path));
                if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory))
                {
                    var filesInDir = Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly);

                    if (filesInDir.Length == 0)
                    {
                        CreateEmptyFolderRecord(directory).Clean();
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 12
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();
            }
        }
Ejemplo n.º 13
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();
        }
Ejemplo n.º 14
0
        private static void ScanFileForIncludes(List <string> referencePaths, string filePath)
        {
            var fileLines = File.ReadAllLines(filePath);

            foreach (var line in fileLines)
            {
                var includeIndex = line.IndexOf("include", StringComparison.Ordinal);
                if (includeIndex == -1)
                {
                    continue;
                }

                var noSharp = line.IndexOf('#', 0, includeIndex) == -1;
                if (noSharp)
                {
                    continue;
                }

                var indexOfFirstQuote = line.IndexOf('"', includeIndex);
                if (indexOfFirstQuote == -1)
                {
                    continue;
                }

                var indexOfLastQuote = line.IndexOf('"', indexOfFirstQuote + 1);
                if (indexOfLastQuote == -1)
                {
                    continue;
                }

                var path = line.Substring(indexOfFirstQuote + 1, indexOfLastQuote - indexOfFirstQuote - 1);
                path = CSPathTools.EnforceSlashes(path);

                string assetPath;

                if (path.StartsWith("Assets/"))
                {
                    assetPath = path;
                }
                else if (path.IndexOf('/') != -1)
                {
                    var folder = System.IO.Path.GetDirectoryName(filePath);
                    if (folder == null)
                    {
                        continue;
                    }

                    var combinedPath = System.IO.Path.Combine(folder, path);
                    var fullPath     = CSPathTools.EnforceSlashes(System.IO.Path.GetFullPath(combinedPath));
                    var assetsIndex  = fullPath.IndexOf("Assets/", StringComparison.Ordinal);
                    if (assetsIndex == -1)
                    {
                        continue;
                    }

                    assetPath = fullPath.Substring(assetsIndex, fullPath.Length - assetsIndex);
                }
                else
                {
                    var folder = System.IO.Path.GetDirectoryName(filePath);
                    if (folder == null)
                    {
                        continue;
                    }

                    assetPath = CSPathTools.EnforceSlashes(System.IO.Path.Combine(folder, path));
                }

                if (!File.Exists(assetPath))
                {
                    continue;
                }

                if (referencePaths.IndexOf(assetPath) != -1)
                {
                    continue;
                }
                {
                    referencePaths.Add(assetPath);
                }
            }
        }
Ejemplo n.º 15
0
        public void UpdateIfNeeded()
        {
            if (string.IsNullOrEmpty(Path))
            {
                Debug.LogWarning(Maintainer.LogPrefix + "Can't update Asset since path is not set!");
                return;
            }

            /*if (Path.Contains("qwerty.unity"))
             * {
             *      Debug.Log(Path);
             * }*/

            fileInfo.Refresh();

            if (!fileInfo.Exists)
            {
                Debug.LogWarning(Maintainer.LogPrefix + "Can't update asset since file at path is not found:\n" + fileInfo.FullName + "\nAsset Path: " + Path);
                return;
            }

            ulong currentHash = 0;

            if (metaFileInfo == null)
            {
                metaFileInfo = new FileInfo(fileInfo.FullName + ".meta");
            }

            metaFileInfo.Refresh();
            if (metaFileInfo.Exists)
            {
                currentHash += (ulong)metaFileInfo.LastWriteTimeUtc.Ticks;
                currentHash += (ulong)metaFileInfo.Length;
            }

            currentHash += (ulong)fileInfo.LastWriteTimeUtc.Ticks;
            currentHash += (ulong)fileInfo.Length;

            if (lastHash == currentHash)
            {
                for (var i = dependenciesGUIDs.Length - 1; i > -1; i--)
                {
                    var guid = dependenciesGUIDs[i];
                    var path = AssetDatabase.GUIDToAssetPath(guid);
                    path = CSPathTools.EnforceSlashes(path);
                    if (!string.IsNullOrEmpty(path) && File.Exists(path))
                    {
                        continue;
                    }

                    ArrayUtility.RemoveAt(ref dependenciesGUIDs, i);
                    foreach (var referenceInfo in assetReferencesInfo)
                    {
                        if (referenceInfo.assetInfo.GUID != guid)
                        {
                            continue;
                        }

                        ArrayUtility.Remove(ref assetReferencesInfo, referenceInfo);
                        break;
                    }
                }

                if (!needToRebuildReferences)
                {
                    return;
                }
            }

            foreach (var referenceInfo in assetReferencesInfo)
            {
                foreach (var info in referenceInfo.assetInfo.referencedAtInfoList)
                {
                    if (info.assetInfo != this)
                    {
                        continue;
                    }

                    ArrayUtility.Remove(ref referenceInfo.assetInfo.referencedAtInfoList, info);
                    break;
                }
            }

            lastHash = currentHash;

            needToRebuildReferences = true;
            Size = fileInfo.Length;

            assetReferencesInfo = new AssetReferenceInfo[0];
            dependenciesGUIDs   = new string[0];

            var dependencies = new List <string>();

            if (SettingsKind == AssetSettingsKind.NotSettings)
            {
                var getRegularDependencies = true;

                /* pre-regular dependencies additions */

                if (Type == CSReflectionTools.assemblyDefinitionAssetType)
                {
                    if (Kind == AssetKind.Regular)
                    {
                        //TODO: check if bug 1020737 is fixed and this can be removed
                        dependencies.AddRange(GetAssetsReferencedFromAssemblyDefinition(Path));
                        getRegularDependencies = false;
                    }
                }

#if UNITY_2019_2_OR_NEWER
                if (Type == CSReflectionTools.assemblyDefinitionReferenceAssetType)
                {
                    if (Kind == AssetKind.Regular)
                    {
                        dependencies.AddRange(GetAssetsReferencedFromAssemblyDefinitionReference(Path));
                        getRegularDependencies = false;
                    }
                }
#endif

#if UNITY_2018_2_OR_NEWER
                // checking by name since addressables are in optional external package
                if (Type != null && Type.Name == "AddressableAssetGroup")
                {
                    var references = AddressablesReferenceFinder.Extract(Path);
                    if (references != null && references.Count > 0)
                    {
                        dependencies.AddRange(references);
                    }
                }
#endif

                /* regular dependencies additions */

                if (getRegularDependencies)
                {
                    dependencies.AddRange(AssetDatabase.GetDependencies(Path, false));
                }

                /* post-regular dependencies additions */

                if (Type == CSReflectionTools.spriteAtlasType)
                {
                    CSArrayTools.TryAddIfNotExists(ref dependencies, GetGetAssetsInFoldersReferencedFromSpriteAtlas(Path));
                }
            }
            else
            {
                dependencies.AddRange(GetAssetsReferencedInPlayerSettingsAsset(Path, SettingsKind));
            }

            // kept for debugging purposes

            /*if (Path.Contains("1.unity"))
             * {
             *      Debug.Log("1.unity non-recursive dependencies:");
             *      foreach (var reference in references)
             *      {
             *              Debug.Log(reference);
             *      }
             * }*/

            if (Type == CSReflectionTools.shaderType)
            {
                // below is an another workaround for dependencies not include #include-ed files, like *.cginc
                ScanFileForIncludes(dependencies, Path);
            }

            if (Type == CSReflectionTools.textAssetType && Path.EndsWith(".cginc"))
            {
                // below is an another workaround for dependencies not include #include-ed files, like *.cginc
                ScanFileForIncludes(dependencies, Path);
            }

            var guids = new string[dependencies.Count];

            for (var i = 0; i < dependencies.Count; i++)
            {
                guids[i] = AssetDatabase.AssetPathToGUID(dependencies[i]);
            }

            dependenciesGUIDs = guids;
        }
Ejemplo n.º 16
0
        public void UpdateIfNeeded()
        {
            if (string.IsNullOrEmpty(Path))
            {
                Debug.LogWarning(Maintainer.LogPrefix + "Can't update Asset since path is not set!");
                return;
            }

            /*if (Path.Contains("qwerty.unity"))
             * {
             *      Debug.Log(Path);
             * }*/

            fileInfo.Refresh();

            if (!fileInfo.Exists)
            {
                Debug.LogWarning(Maintainer.LogPrefix + "Can't update asset since file at path is not found:\n" + fileInfo.FullName + "\nAsset Path: " + Path);
                return;
            }

            ulong currentHash = 0;

            if (metaFileInfo == null)
            {
                metaFileInfo = new FileInfo(fileInfo.FullName + ".meta");
            }

            metaFileInfo.Refresh();
            if (metaFileInfo.Exists)
            {
                currentHash += (ulong)metaFileInfo.LastWriteTimeUtc.Ticks;
                currentHash += (ulong)metaFileInfo.Length;
            }

            currentHash += (ulong)fileInfo.LastWriteTimeUtc.Ticks;
            currentHash += (ulong)fileInfo.Length;

            if (lastHash == currentHash)
            {
                for (var i = dependenciesGUIDs.Length - 1; i > -1; i--)
                {
                    var guid = dependenciesGUIDs[i];
                    var path = AssetDatabase.GUIDToAssetPath(guid);
                    path = CSPathTools.EnforceSlashes(path);
                    if (!string.IsNullOrEmpty(path) && File.Exists(path))
                    {
                        continue;
                    }

                    ArrayUtility.RemoveAt(ref dependenciesGUIDs, i);
                    foreach (var referenceInfo in assetReferencesInfo)
                    {
                        if (referenceInfo.assetInfo.GUID != guid)
                        {
                            continue;
                        }

                        ArrayUtility.Remove(ref assetReferencesInfo, referenceInfo);
                        break;
                    }
                }

                if (!needToRebuildReferences)
                {
                    return;
                }
            }

            foreach (var referenceInfo in assetReferencesInfo)
            {
                foreach (var info in referenceInfo.assetInfo.referencedAtInfoList)
                {
                    if (info.assetInfo != this)
                    {
                        continue;
                    }

                    ArrayUtility.Remove(ref referenceInfo.assetInfo.referencedAtInfoList, info);
                    break;
                }
            }

            lastHash = currentHash;

            needToRebuildReferences = true;
            Size = fileInfo.Length;

            assetReferencesInfo = new AssetReferenceInfo[0];
            dependenciesGUIDs   = AssetDependenciesSearcher.FindDependencies(SettingsKind, Type, Kind, Path);
        }