private void DeleteRecords() { for (var i = recordsToDeleteIndexes.Length - 1; i >= 0; i--) { var index = recordsToDeleteIndexes[i]; var record = filteredRecords[index]; records = CSArrayTools.RemoveAt(records, Array.IndexOf(records, record)); GetState().selection.RemoveAt(index); GetState().compaction.RemoveAt(index); } recordsToDeleteIndexes = null; ApplySorting(); if (filteredRecords.Length > 0) { recordsTotalPages = (int)Math.Ceiling((double)filteredRecords.Length / RecordsPerPage); } else { recordsTotalPages = 1; } if (recordsCurrentPage + 1 > recordsTotalPages) { recordsCurrentPage = recordsTotalPages - 1; } SaveSearchResults(); window.Repaint(); }
private void DrawMoreButton(GameObjectIssueRecord record) { if (!UIHelpers.RecordButton(record, "Shows menu with additional actions for this record.", CSIcons.More)) { return; } GenericMenu menu = new GenericMenu(); if (!string.IsNullOrEmpty(record.path)) { menu.AddItem(new GUIContent("Ignore/Add path to ignores"), false, () => { if (CSArrayTools.AddIfNotExists(ref MaintainerSettings.Issues.pathIgnores, record.path)) { MaintainerWindow.ShowNotification("Ignore added: " + record.path); IssuesFiltersWindow.Refresh(); } else { MaintainerWindow.ShowNotification("Such item already added to the ignores!"); } }); DirectoryInfo dir = Directory.GetParent(record.path); if (dir.Name != "Assets") { menu.AddItem(new GUIContent("Ignore/Add parent directory to ignores"), false, () => { if (CSArrayTools.AddIfNotExists(ref MaintainerSettings.Issues.pathIgnores, dir.ToString())) { MaintainerWindow.ShowNotification("Ignore added: " + dir); IssuesFiltersWindow.Refresh(); } else { MaintainerWindow.ShowNotification("Such item already added to the ignores!"); } }); } } if (!string.IsNullOrEmpty(record.componentName)) { menu.AddItem(new GUIContent("Ignore/Add component to ignores"), false, () => { if (CSArrayTools.AddIfNotExists(ref MaintainerSettings.Issues.componentIgnores, record.componentName)) { MaintainerWindow.ShowNotification("Ignore added: " + record.componentName); IssuesFiltersWindow.Refresh(); } else { MaintainerWindow.ShowNotification("Such item already added to the ignores!"); } }); } menu.ShowAsContext(); }
private void DrawRecordButtons(RecordBase record) { using (UIHelpers.Horizontal(UIHelpers.panelWithBackground)) { AddShowButtonIfPossible(record); AssetRecord assetRecord = record as AssetRecord; if (assetRecord != null) { if (GUILayout.Button(new GUIContent("Reveal", "Reveals item in system default File Manager like Explorer on Windows or Finder on Mac."), UIHelpers.recordButton)) { EditorUtility.RevealInFinder(assetRecord.path); } if (GUILayout.Button("More ...", UIHelpers.recordButton)) { GenericMenu menu = new GenericMenu(); if (!string.IsNullOrEmpty(assetRecord.path)) { menu.AddItem(new GUIContent("Ignore/Add path to ignores"), false, () => { if (CSArrayTools.AddIfNotExists(ref MaintainerSettings.Cleaner.pathIgnores, assetRecord.assetDatabasePath)) { MaintainerSettings.Save(); MaintainerWindow.ShowNotification("Ignore added: " + assetRecord.assetDatabasePath); CleanerIgnoresWindow.Refresh(); } else { MaintainerWindow.ShowNotification("Such item already added to the ignores!"); } }); DirectoryInfo dir = Directory.GetParent(assetRecord.assetDatabasePath); if (dir.Name != "Assets") { menu.AddItem(new GUIContent("Ignore/Add parent directory to ignores"), false, () => { if (CSArrayTools.AddIfNotExists(ref MaintainerSettings.Cleaner.pathIgnores, dir.ToString())) { MaintainerSettings.Save(); MaintainerWindow.ShowNotification("Ignore added: " + dir); CleanerIgnoresWindow.Refresh(); } else { MaintainerWindow.ShowNotification("Such item already added to the ignores!"); } }); } } menu.ShowAsContext(); } } } }
public static SettingsIssueRecord CheckTagsAndLayers() { var issueBody = new StringBuilder(); /* looking for duplicates in layers */ var layers = new List <string>(InternalEditorUtility.layers); layers.RemoveAll(string.IsNullOrEmpty); var duplicateLayers = CSArrayTools.FindDuplicatesInArray(layers); if (duplicateLayers.Count > 0) { if (issueBody.Length > 0) { issueBody.AppendLine(); } issueBody.Append("Duplicate <b>layer(s)</b>: "); foreach (var duplicate in duplicateLayers) { issueBody.Append('"').Append(duplicate).Append("\", "); } issueBody.Length -= 2; } /* looking for duplicates in sorting layers */ var sortingLayers = new List <string>((string[])CSReflectionTools.GetSortingLayersPropertyInfo().GetValue(null, new object[0])); sortingLayers.RemoveAll(string.IsNullOrEmpty); var duplicateSortingLayers = CSArrayTools.FindDuplicatesInArray(sortingLayers); if (duplicateSortingLayers.Count > 0) { if (issueBody.Length > 0) { issueBody.AppendLine(); } issueBody.Append("Duplicate <b>sorting layer(s)</b>: "); foreach (var duplicate in duplicateSortingLayers) { issueBody.Append('"').Append(duplicate).Append("\", "); } issueBody.Length -= 2; } if (issueBody.Length > 0) { return(SettingsIssueRecord.Create(AssetSettingsKind.TagManager, IssueKind.DuplicateLayers, issueBody.ToString())); } return(null); }
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 (!CSArrayTools.IsItemContainsAnyStringFromArray(folder, emptyFoldersFiltered)) { emptyFoldersFiltered.Add(folder); } } emptyFolders = emptyFoldersFiltered; }
private static void CheckBuildSettings(List <IssueRecord> issues) { if (MaintainerSettings.Issues.duplicateScenesInBuild) { string[] scenesForBuild = GetEnabledScenesInBuild(); string[] duplicates = CSArrayTools.FindDuplicatesInArray(scenesForBuild); foreach (var duplicate in duplicates) { issues.Add(BuildSettingsIssueRecord.Create(RecordType.DuplicateScenesInBuild, "<b>Duplicate scene:</b> " + CSEditorTools.NicifyAssetPath(duplicate))); } } }
private void DrawMoreButton(AssetRecord assetRecord) { if (UIHelpers.RecordButton(assetRecord, "Shows menu with additional actions for this record.", CSIcons.More)) { GenericMenu menu = new GenericMenu(); if (!string.IsNullOrEmpty(assetRecord.path)) { menu.AddItem(new GUIContent("Ignore/Add path to ignores"), false, () => { if (CSArrayTools.AddIfNotExists(ref MaintainerSettings.Cleaner.pathIgnores, assetRecord.assetDatabasePath)) { MaintainerWindow.ShowNotification("Ignore added: " + assetRecord.assetDatabasePath); CleanerFiltersWindow.Refresh(); } else { MaintainerWindow.ShowNotification("Such item already added to the ignores!"); } }); DirectoryInfo dir = Directory.GetParent(assetRecord.assetDatabasePath); if (dir.Name != "Assets") { menu.AddItem(new GUIContent("Ignore/Add parent directory to ignores"), false, () => { if (CSArrayTools.AddIfNotExists(ref MaintainerSettings.Cleaner.pathIgnores, dir.ToString())) { MaintainerWindow.ShowNotification("Ignore added: " + dir); CleanerFiltersWindow.Refresh(); } else { MaintainerWindow.ShowNotification("Such item already added to the ignores!"); } }); } } menu.ShowAsContext(); } }
protected virtual void DeleteRecord() { T record = filteredRecords[recordToDeleteIndex]; records = CSArrayTools.RemoveAt(records, Array.IndexOf(records, record)); ApplySorting(); if (filteredRecords.Length > 0) { recordsTotalPages = (int)Math.Ceiling((double)filteredRecords.Length / RECORDS_PER_PAGE); } else { recordsTotalPages = 1; } if (recordsCurrentPage + 1 > recordsTotalPages) { recordsCurrentPage = recordsTotalPages - 1; } SaveSearchResults(); window.Repaint(); }
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; }
protected override void DrawRecord(int recordIndex, out bool recordRemoved) { recordRemoved = false; RecordBase record = records[recordIndex]; UIHelpers.Separator(); using (UIHelpers.Horizontal()) { DrawSeverityIcon(record); if (record.location == RecordLocation.Prefab) { UIHelpers.DrawPrefabIcon(); } GUILayout.Label(record.GetHeader(), UIHelpers.richLabel, GUILayout.ExpandWidth(false)); } GUILayout.Label(record.GetBody(), UIHelpers.richLabel); using (UIHelpers.Horizontal(UIHelpers.panelWithBackground)) { AddShowButtonIfPossible(record); if (GUILayout.Button(new GUIContent("Copy", "Copies record text to the clipboard."), UIHelpers.recordButton)) { EditorGUIUtility.systemCopyBuffer = record.ToString(true); MaintainerWindow.ShowNotification("Issue record copied to clipboard!"); } if (GUILayout.Button(new GUIContent("Hide", "Hide this issue from the results list.\nUseful when you fixed issue and wish to hide it away."), UIHelpers.recordButton)) { // ReSharper disable once CoVariantArrayConversion records = CSArrayTools.RemoveAt(records as IssueRecord[], recordIndex); SearchResultsStorage.IssuesSearchResults = (IssueRecord[])records; recordRemoved = true; return; } //UIHelpers.VerticalSeparator(); GameObjectIssueRecord objectIssue = record as GameObjectIssueRecord; if (objectIssue != null) { if (GUILayout.Button("More ...", UIHelpers.recordButton)) { GenericMenu menu = new GenericMenu(); if (!string.IsNullOrEmpty(objectIssue.path)) { menu.AddItem(new GUIContent("Ignore/Add path to ignores"), false, () => { if (CSArrayTools.AddIfNotExists(ref MaintainerSettings.Issues.pathIgnores, objectIssue.path)) { MaintainerSettings.Save(); MaintainerWindow.ShowNotification("Ignore added: " + objectIssue.path); IssuesIgnoresWindow.Refresh(); } else { MaintainerWindow.ShowNotification("Such item already added to the ignores!"); } }); DirectoryInfo dir = Directory.GetParent(objectIssue.path); if (dir.Name != "Assets") { menu.AddItem(new GUIContent("Ignore/Add parent directory to ignores"), false, () => { if (CSArrayTools.AddIfNotExists(ref MaintainerSettings.Issues.pathIgnores, dir.ToString())) { MaintainerSettings.Save(); MaintainerWindow.ShowNotification("Ignore added: " + dir); IssuesIgnoresWindow.Refresh(); } else { MaintainerWindow.ShowNotification("Such item already added to the ignores!"); } }); } } if (!string.IsNullOrEmpty(objectIssue.component)) { menu.AddItem(new GUIContent("Ignore/Add component to ignores"), false, () => { if (CSArrayTools.AddIfNotExists(ref MaintainerSettings.Issues.componentIgnores, objectIssue.component)) { MaintainerSettings.Save(); MaintainerWindow.ShowNotification("Ignore added: " + objectIssue.component); IssuesIgnoresWindow.Refresh(); } else { MaintainerWindow.ShowNotification("Such item already added to the ignores!"); } }); } menu.ShowAsContext(); } } } }
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; }
private static bool FindEmptyFoldersRecursive(List <string> foundEmptyFolders, string root, bool showProgress, out bool canceledByUser) { string[] rootSubFolders = Directory.GetDirectories(root); bool canceled = false; bool emptySubFolders = true; foreach (string folder in rootSubFolders) { folderIndex++; if (showProgress && EditorUtility.DisplayCancelableProgressBar(string.Format(PROGRESS_CAPTION, currentPhase, phasesCount, folderIndex, foldersCount), "Scanning folders...", (float)folderIndex / foldersCount)) { canceled = true; break; } if (CSArrayTools.IsItemContainsAnyStringFromArray(folder.Replace('\\', '/'), MaintainerSettings.Cleaner.pathIgnores)) { emptySubFolders = false; continue; } if (Path.GetFileName(folder).StartsWith(".")) { continue; } emptySubFolders &= FindEmptyFoldersRecursive(foundEmptyFolders, folder, showProgress, out canceled); if (canceled) { break; } } if (canceled) { canceledByUser = true; return(false); } bool rootFolderHasFiles = true; string[] filesInRootFolder = Directory.GetFiles(root); foreach (string file in filesInRootFolder) { if (file.EndsWith(".meta")) { continue; } rootFolderHasFiles = false; break; } bool rootFolderEmpty = emptySubFolders && rootFolderHasFiles; if (rootFolderEmpty) { foundEmptyFolders.Add(root); } canceledByUser = false; return(rootFolderEmpty); }
private static void CheckTagsAndLayers(List <IssueRecord> issues) { if (MaintainerSettings.Issues.duplicateTagsAndLayers) { StringBuilder issueBody = new StringBuilder(); /* looking for duplicates in tags*/ List <string> tags = new List <string>(InternalEditorUtility.tags); tags.RemoveAll(string.IsNullOrEmpty); List <string> duplicateTags = CSArrayTools.FindDuplicatesInArray(tags); if (duplicateTags.Count > 0) { issueBody.Append("Duplicate <b>tag(s)</b>: "); foreach (var duplicate in duplicateTags) { issueBody.Append('"').Append(duplicate).Append("\", "); } issueBody.Length -= 2; } /* looking for duplicates in layers*/ List <string> layers = new List <string>(InternalEditorUtility.layers); layers.RemoveAll(string.IsNullOrEmpty); List <string> duplicateLayers = CSArrayTools.FindDuplicatesInArray(layers); if (duplicateLayers.Count > 0) { if (issueBody.Length > 0) { issueBody.AppendLine(); } issueBody.Append("Duplicate <b>layer(s)</b>: "); foreach (var duplicate in duplicateLayers) { issueBody.Append('"').Append(duplicate).Append("\", "); } issueBody.Length -= 2; } /* looking for duplicates in sorting layers*/ Type internalEditorUtilityType = typeof(InternalEditorUtility); PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic); List <string> sortingLayers = new List <string>((string[])sortingLayersProperty.GetValue(null, new object[0])); sortingLayers.RemoveAll(string.IsNullOrEmpty); List <string> duplicateSortingLayers = CSArrayTools.FindDuplicatesInArray(sortingLayers); if (duplicateSortingLayers.Count > 0) { if (issueBody.Length > 0) { issueBody.AppendLine(); } issueBody.Append("Duplicate <b>sorting layer(s)</b>: "); foreach (var duplicate in duplicateSortingLayers) { issueBody.Append('"').Append(duplicate).Append("\", "); } issueBody.Length -= 2; } if (issueBody.Length > 0) { issues.Add(TagsAndLayersIssueRecord.Create(RecordType.DuplicateTagsAndLayers, issueBody.ToString())); } issueBody.Length = 0; } }