diff --git a/CHANGELOG.md b/CHANGELOG.md index b18d189..43e3b5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,6 @@ +## [1.0.2] - 03/05/2023 +### Fixed +- O campo privado `[t:CancellationTokenSource]NoWarning.source` foi substituido por `[t:bool]NoWarning.cancel` por provocar referencia nula inesperadamente apos fechar a janela. +- Agora o Suppressor Warning verifica a pasta Assets em busca por Assemblies. ## [1.0.0] - 01/05/2023 - Pacote `com.cobilas.unity.warningsuppressor` criado. \ No newline at end of file diff --git a/Editor/NoWarningContainer.cs b/Editor/NoWarningContainer.cs index 5df6fd6..091f0d9 100644 --- a/Editor/NoWarningContainer.cs +++ b/Editor/NoWarningContainer.cs @@ -4,9 +4,15 @@ [Serializable] public sealed class NoWarningContainer { public byte status; + [NonSerialized] + public ulong timer; + [NonSerialized] + public bool cancel; + [NonSerialized] + public bool isCompleted; public bool showNoVisibles; public string globalNoWarning; - [NonSerialized] public bool isCompleted; + public List IndividualNoWarning; diff --git a/Editor/NoWarningWindow.cs b/Editor/NoWarningWindow.cs index 531d228..3836457 100644 --- a/Editor/NoWarningWindow.cs +++ b/Editor/NoWarningWindow.cs @@ -2,7 +2,6 @@ using UnityEditor; using UnityEngine; using System.Text; -using System.Threading; using System.Collections; using UnityEditorInternal; using UnityEditor.PackageManager; @@ -22,7 +21,6 @@ static void DoIt() { private Vector2 scrollView2; [SerializeField] private NoWarningContainer container; - private CancellationTokenSource source; //IDE0015;IDE0051>~M:NoWarningWindow.tds; private string ContainerPath { @@ -40,15 +38,14 @@ private void OnEnable() { return; } container = JsonUtility.FromJson(File.ReadAllText(ContainerPath)); - source = new CancellationTokenSource(); - _ = EditorCoroutineUtility.StartCoroutine(GetAssembles(container, source), this); + _ = EditorCoroutineUtility.StartCoroutine(GetAssembles(this), this); } private void OnDisable() => Unload(); private void OnDestroy() { - source.Cancel(); + container.cancel = true; Unload(); } @@ -103,30 +100,35 @@ private void CreateWarningSuppressorFile(string filePath, string suppressor) { private void OnGUI() { EditorGUILayout.BeginHorizontal(); - EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Width(160f), GUILayout.ExpandHeight(true)); - EditorGUI.BeginDisabledGroup(!container.isCompleted); - scrollView1 = EditorGUILayout.BeginScrollView(scrollView1); - if (GUILayout.Button(GUIContentTemp.bt_save)) - OnDisable(); - if (GUILayout.Button(GUIContentTemp.bt_applayNoWar)) - ApplayNoWarning(container); - if (GUILayout.Button(GUIContentTemp.bt_globalNoWar)) - container.status = 0; - if (GUILayout.Button(GUIContentTemp.bt_IndividualNoWar)) - container.status = 1; - EditorGUILayout.EndScrollView(); - EditorGUILayout.EndVertical(); - scrollView2 = EditorGUILayout.BeginScrollView(scrollView2); - switch (container.status) { - case 0: - DrawGlobalNoWar(container); - break; - case 1: - DrawIndividualNoWar(container); - break; - } - EditorGUILayout.EndScrollView(); - EditorGUI.EndDisabledGroup(); + EditorGUILayout.BeginVertical(GUILayout.Width(160f)); + EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.ExpandHeight(true)); + EditorGUI.BeginDisabledGroup(!container.isCompleted); + scrollView1 = EditorGUILayout.BeginScrollView(scrollView1); + if (GUILayout.Button(GUIContentTemp.bt_save)) + OnDisable(); + if (GUILayout.Button(GUIContentTemp.bt_applayNoWar)) + ApplayNoWarning(container); + if (GUILayout.Button(GUIContentTemp.bt_globalNoWar)) + container.status = 0; + if (GUILayout.Button(GUIContentTemp.bt_IndividualNoWar)) + container.status = 1; + EditorGUILayout.EndScrollView(); + EditorGUI.EndDisabledGroup(); + EditorGUILayout.EndVertical(); + GUILayout.Box(EditorGUIUtility.TrTempContent($"Timer: {container.timer}t"), GUIContentTemp.HelpBoxBlood); + EditorGUILayout.EndVertical(); + EditorGUI.BeginDisabledGroup(!container.isCompleted); + scrollView2 = EditorGUILayout.BeginScrollView(scrollView2); + switch (container.status) { + case 0: + DrawGlobalNoWar(container); + break; + case 1: + DrawIndividualNoWar(container); + break; + } + EditorGUILayout.EndScrollView(); + EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); } @@ -182,44 +184,66 @@ private void DrawGlobalNoWar(NoWarningContainer container) { EditorGUILayout.EndVertical(); } - private IEnumerator GetAssembles(NoWarningContainer container, CancellationTokenSource source) { + private IEnumerator GetAssembles(NoWarningWindow container) { ListRequest search = Client.List(true); - container.isCompleted = false; - foreach (var item in container.IndividualNoWarning) - item.isVisible = container.isCompleted; + container.container.isCompleted = false; + foreach (var item in container.container.IndividualNoWarning) + item.isVisible = container.container.isCompleted; + container.container.timer = 0UL; - yield return new WaitWhile(() => !search.IsCompleted && !source.IsCancellationRequested); - if (!source.IsCancellationRequested) { + yield return new WaitWhile(() => { + if (++container.container.timer % 30 == 0) + container.Repaint(); + return !search.IsCompleted && !container.container.cancel; + }); + if (!container.container.cancel) { string pj_path = Path.GetDirectoryName(Application.dataPath); string[] paths = new string[1]; + paths[0] = "Assets"; + foreach (var item2 in AssetDatabase.FindAssets($"t:{nameof(AssemblyDefinitionAsset)}", paths)) { + paths[0] = AssetDatabase.GUIDToAssetPath(item2); + if (container.container.ContainsAssembly(Path.GetFileName(paths[0]))) { + string name = Path.GetFileName(paths[0]); + int index = container.container.IndexOf(name); + container.container.IndividualNoWarning[index].isVisible = true; + container.container.IndividualNoWarning[index].assemblyDefinitionName = name; + container.container.IndividualNoWarning[index].assemblyDefinitionPath = paths[0]; + } else { + NoWarningContainer.IndivNoWar noWarning = new NoWarningContainer.IndivNoWar(); + noWarning.assemblyDefinitionPath = paths[0]; + noWarning.assemblyDefinitionName = Path.GetFileName(paths[0]); + container.container.IndividualNoWarning.Add(noWarning); + } + } foreach (var item in search.Result) { if (item.source != PackageSource.Embedded) continue; paths[0] = item.resolvedPath.Replace(pj_path, string.Empty).TrimStart('/', '\\'); foreach (var item2 in AssetDatabase.FindAssets($"t:{nameof(AssemblyDefinitionAsset)}", paths)) { paths[0] = AssetDatabase.GUIDToAssetPath(item2); - if (container.ContainsAssembly(Path.GetFileName(paths[0]))) { + if (container.container.ContainsAssembly(Path.GetFileName(paths[0]))) { string name = Path.GetFileName(paths[0]); - int index = container.IndexOf(name); - container.IndividualNoWarning[index].isVisible = true; - container.IndividualNoWarning[index].assemblyDefinitionName = name; - container.IndividualNoWarning[index].assemblyDefinitionPath = paths[0]; + int index = container.container.IndexOf(name); + container.container.IndividualNoWarning[index].isVisible = true; + container.container.IndividualNoWarning[index].assemblyDefinitionName = name; + container.container.IndividualNoWarning[index].assemblyDefinitionPath = paths[0]; } else { NoWarningContainer.IndivNoWar noWarning = new NoWarningContainer.IndivNoWar(); noWarning.assemblyDefinitionPath = paths[0]; noWarning.assemblyDefinitionName = Path.GetFileName(paths[0]); - container.IndividualNoWarning.Add(noWarning); + container.container.IndividualNoWarning.Add(noWarning); } } } - foreach (var item in container.IndividualNoWarning) { + foreach (var item in container.container.IndividualNoWarning) { string filePath = Path.Combine(pj_path, item.assemblyDefinitionPath); if (!File.Exists(filePath) && File.Exists($"{filePath}.nowar.cs")) File.Delete($"{filePath}.nowar.cs"); } - container.isCompleted = true; + container.container.isCompleted = true; + container.Repaint(); } } @@ -233,5 +257,18 @@ internal static class GUIContentTemp { internal static readonly GUIContent bt_IndividualNoWar = new GUIContent("Individual no warning", "Local warning suppression settings where each automaker can receive its own suppression."); internal static readonly GUIContent tg_applayglobalNoWar = new GUIContent("Applay global no warning", "If 'Apply no warning' is not checked, the global warning suppressor will be used."); + private static GUIStyle helpBoxBlood = (GUIStyle)null; + + internal static GUIStyle HelpBoxBlood { + get { + if (helpBoxBlood == null) { + helpBoxBlood = new GUIStyle(EditorStyles.helpBox); + helpBoxBlood.fontSize = 12; + helpBoxBlood.fontStyle = FontStyle.Bold; + helpBoxBlood.alignment = TextAnchor.MiddleLeft; + } + return helpBoxBlood; + } + } } } \ No newline at end of file diff --git a/package.json b/package.json index 4f36728..1f5345e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.cobilas.unity.warningsuppressor", - "version": "1.0.0", + "version": "1.0.2", "description": "Supressor de avisos do editor de codigo para unity.", "type": "tool", "displayName": "Warning Suppressor",