From f7a7427610179039a4ff9655296b94dcb9d5720c Mon Sep 17 00:00:00 2001 From: Kamila Stawarska Date: Mon, 3 Mar 2025 19:17:05 +0100 Subject: [PATCH] clean up --- AutoSceneChanger.cs | 1 - Editor/BuildingUtils.cs | 2 ++ Editor/ToolsWindowBase.cs | 2 ++ KeyBasedFactory.cs | 2 ++ NEG/UI/PriorityQueue.cs | 22 ++++++++++--------- NEG/UI/UnityUi/Area/MonoArea.cs | 2 +- NEG/UI/UnityUi/Buttons/BaseButton.cs | 5 +---- NEG/UI/UnityUi/Buttons/Reactions/ExitGame.cs | 3 ++- NEG/UI/UnityUi/MonoUiInputManger.cs | 2 ++ NEG/UI/UnityUi/Window/MonoWindow.cs | 4 ++-- NEG/Utils/ReadOnlyAttribute.cs | 1 - .../MultiSelectChips/MultiSelectChips.cs | 5 +++-- .../Resources/MultiSelectChipItem.uxml | 2 +- .../Resources/MultiSelectChips.uxml | 2 +- 14 files changed, 31 insertions(+), 24 deletions(-) diff --git a/AutoSceneChanger.cs b/AutoSceneChanger.cs index eac7d74..416df6f 100644 --- a/AutoSceneChanger.cs +++ b/AutoSceneChanger.cs @@ -1,5 +1,4 @@ using UnityEngine; -using UnityEngine.SceneManagement; namespace NEG.Utils { diff --git a/Editor/BuildingUtils.cs b/Editor/BuildingUtils.cs index cd507f2..062a052 100644 --- a/Editor/BuildingUtils.cs +++ b/Editor/BuildingUtils.cs @@ -185,8 +185,10 @@ public static class BuildingUtils string command = $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && push_build.bat"; if (demo) + { command = $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && push_demo.bat"; + } var processInfo = new ProcessStartInfo("cmd.exe", $"/c {command}") { diff --git a/Editor/ToolsWindowBase.cs b/Editor/ToolsWindowBase.cs index c5f0ea2..e275c7a 100644 --- a/Editor/ToolsWindowBase.cs +++ b/Editor/ToolsWindowBase.cs @@ -102,8 +102,10 @@ namespace NegUtils.Editor return; if (EditorPrefs.GetBool("GoToCurrentSceneAfterPlay")) + { EditorSceneManager.LoadSceneInPlayMode(EditorPrefs.GetString("LastOpenedScenePath"), new LoadSceneParameters(LoadSceneMode.Single)); + } else if (EditorPrefs.GetBool("GoToFirstSceneAfterPlay")) SceneManager.LoadScene(1); } diff --git a/KeyBasedFactory.cs b/KeyBasedFactory.cs index 8ff9c46..57b3091 100644 --- a/KeyBasedFactory.cs +++ b/KeyBasedFactory.cs @@ -31,8 +31,10 @@ namespace NEG.Utils var methodFields = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); for (int i = 0; i < methodFields.Length; i++) + { if (Attribute.GetCustomAttribute(methodFields[i], typeof(FactoryRegistration)) != null) methodFields[i].Invoke(null, Array.Empty()); + } } } diff --git a/NEG/UI/PriorityQueue.cs b/NEG/UI/PriorityQueue.cs index 591e85f..fbe8ef8 100644 --- a/NEG/UI/PriorityQueue.cs +++ b/NEG/UI/PriorityQueue.cs @@ -248,8 +248,10 @@ namespace System.Collections.Generic public PriorityQueue(int initialCapacity, IComparer? comparer) { if (initialCapacity < 0) + { throw new ArgumentOutOfRangeException( nameof(initialCapacity), initialCapacity, SR.ArgumentOutOfRange_NeedNonNegNum); + } _nodes = new (TElement, TPriority)[initialCapacity]; _comparer = InitializeComparer(comparer); @@ -508,9 +510,8 @@ namespace System.Collections.Generic if (_size > 1) Heapify(); } else - { - foreach (var (element, priority) in items) Enqueue(element, priority); - } + foreach (var (element, priority) in items) + Enqueue(element, priority); } /// @@ -554,9 +555,8 @@ namespace System.Collections.Generic if (i > 1) Heapify(); } else - { - foreach (var element in elements) Enqueue(element, priority); - } + foreach (var element in elements) + Enqueue(element, priority); } /// @@ -684,11 +684,15 @@ namespace System.Collections.Generic int lastParentWithChildren = GetParentIndex(_size - 1); if (_comparer == null) + { for (int index = lastParentWithChildren; index >= 0; --index) MoveDownDefaultComparer(nodes[index], index); + } else + { for (int index = lastParentWithChildren; index >= 0; --index) MoveDownCustomComparer(nodes[index], index); + } } /// @@ -715,9 +719,7 @@ namespace System.Collections.Generic nodeIndex = parentIndex; } else - { break; - } } nodes[nodeIndex] = node; @@ -748,9 +750,7 @@ namespace System.Collections.Generic nodeIndex = parentIndex; } else - { break; - } } nodes[nodeIndex] = node; @@ -894,8 +894,10 @@ namespace System.Collections.Generic if (array.GetLowerBound(0) != 0) throw new ArgumentException(SR.Arg_NonZeroLowerBound, nameof(array)); if (index < 0 || index > array.Length) + { throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_IndexMustBeLessOrEqual); + } if (array.Length - index < _queue._size) throw new ArgumentException(SR.Argument_InvalidOffLen); diff --git a/NEG/UI/UnityUi/Area/MonoArea.cs b/NEG/UI/UnityUi/Area/MonoArea.cs index 96d9c77..dd42469 100644 --- a/NEG/UI/UnityUi/Area/MonoArea.cs +++ b/NEG/UI/UnityUi/Area/MonoArea.cs @@ -29,7 +29,7 @@ namespace NEG.UI.Area private void OnDestroy() { - if(UiManager.Instance == null) + if (UiManager.Instance == null) return; if (ReferenceEquals(UiManager.Instance.CurrentArea, this)) UiManager.Instance.CurrentArea = null; diff --git a/NEG/UI/UnityUi/Buttons/BaseButton.cs b/NEG/UI/UnityUi/Buttons/BaseButton.cs index 7c605df..d757dc9 100644 --- a/NEG/UI/UnityUi/Buttons/BaseButton.cs +++ b/NEG/UI/UnityUi/Buttons/BaseButton.cs @@ -43,10 +43,7 @@ namespace NEG.UI.UnityUi.Buttons private void Start() => OnDeselect(null); - private void OnValidate() - { - this.ValidateRefs(); - } + private void OnValidate() => this.ValidateRefs(); public void OnDeselect(BaseEventData eventData) => OnDeselected?.Invoke(eventData is SilentEventData); diff --git a/NEG/UI/UnityUi/Buttons/Reactions/ExitGame.cs b/NEG/UI/UnityUi/Buttons/Reactions/ExitGame.cs index f870bb6..a62d5c9 100644 --- a/NEG/UI/UnityUi/Buttons/Reactions/ExitGame.cs +++ b/NEG/UI/UnityUi/Buttons/Reactions/ExitGame.cs @@ -1,3 +1,4 @@ +using UnityEditor; using UnityEngine; namespace NEG.UI.UnityUi.Buttons.Reactions @@ -7,7 +8,7 @@ namespace NEG.UI.UnityUi.Buttons.Reactions protected override void OnClicked() { #if UNITY_EDITOR - UnityEditor.EditorApplication.isPlaying = false; + EditorApplication.isPlaying = false; #endif Application.Quit(); } diff --git a/NEG/UI/UnityUi/MonoUiInputManger.cs b/NEG/UI/UnityUi/MonoUiInputManger.cs index 846c91d..53c60bd 100644 --- a/NEG/UI/UnityUi/MonoUiInputManger.cs +++ b/NEG/UI/UnityUi/MonoUiInputManger.cs @@ -74,10 +74,12 @@ namespace NEG.UI.UnityUi var data = new PointerEventData(EventSystem.current); var currentSelected = EventSystem.current.currentSelectedGameObject; if (currentSelected != null) + { for (var current = EventSystem.current.currentSelectedGameObject.transform; current != null; current = current.parent) ExecuteEvents.Execute(current.gameObject, data, ExecuteEvents.pointerExitHandler); + } EventSystem.current.SetSelectedGameObject(currentSelected); } diff --git a/NEG/UI/UnityUi/Window/MonoWindow.cs b/NEG/UI/UnityUi/Window/MonoWindow.cs index 6d9639e..5f526a0 100644 --- a/NEG/UI/UnityUi/Window/MonoWindow.cs +++ b/NEG/UI/UnityUi/Window/MonoWindow.cs @@ -27,9 +27,9 @@ namespace NEG.UI.UnityUi.Window private void OnDestroy() { - if(UiManager.Instance == null) + if (UiManager.Instance == null) return; - if (IsOpened) + if (IsOpened) UiManager.Instance.OnWindowClosed(this); } diff --git a/NEG/Utils/ReadOnlyAttribute.cs b/NEG/Utils/ReadOnlyAttribute.cs index 3f5409c..b5fda1f 100644 --- a/NEG/Utils/ReadOnlyAttribute.cs +++ b/NEG/Utils/ReadOnlyAttribute.cs @@ -5,5 +5,4 @@ namespace NEG.Utils public class ReadOnlyAttribute : PropertyAttribute { } - } \ No newline at end of file diff --git a/UiToolkit/MultiSelectChips/MultiSelectChips.cs b/UiToolkit/MultiSelectChips/MultiSelectChips.cs index a06f386..6250b26 100644 --- a/UiToolkit/MultiSelectChips/MultiSelectChips.cs +++ b/UiToolkit/MultiSelectChips/MultiSelectChips.cs @@ -10,9 +10,8 @@ namespace NEG.Utils.UiToolkits { public class MultiSelectChips : VisualElement { - private readonly List spawnedItems = new(); - private readonly VisualTreeAsset itemPrefab; + private readonly List spawnedItems = new(); private ICollection itemsSource; @@ -86,8 +85,10 @@ namespace NEG.Utils.UiToolkits List itemsToAdd = new(itemsSource); foreach (var item in spawnedItems) + { if (itemsToAdd.Contains(item.ChipItem)) itemsToAdd.Remove(item.ChipItem); + } foreach (var item in itemsToAdd) { diff --git a/UiToolkit/MultiSelectChips/Resources/MultiSelectChipItem.uxml b/UiToolkit/MultiSelectChips/Resources/MultiSelectChipItem.uxml index bff6dfa..8a4773a 100644 --- a/UiToolkit/MultiSelectChips/Resources/MultiSelectChipItem.uxml +++ b/UiToolkit/MultiSelectChips/Resources/MultiSelectChipItem.uxml @@ -1,4 +1,4 @@ -