Skip to content

Commit

Permalink
#Update-vs1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
BelicusBr committed May 3, 2023
1 parent 583da45 commit ff9f767
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 45 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 7 additions & 1 deletion Editor/NoWarningContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndivNoWar> IndividualNoWarning;

Expand Down
123 changes: 80 additions & 43 deletions Editor/NoWarningWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using UnityEditor;
using UnityEngine;
using System.Text;
using System.Threading;
using System.Collections;
using UnityEditorInternal;
using UnityEditor.PackageManager;
Expand All @@ -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 {
Expand All @@ -40,15 +38,14 @@ private void OnEnable() {
return;
}
container = JsonUtility.FromJson<NoWarningContainer>(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();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}
}

Expand All @@ -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;
}
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit ff9f767

Please sign in to comment.