diff --git a/NEG/UI/Popup/IPopup.cs b/NEG/UI/Popup/IPopup.cs index 1813467..e3468c7 100644 --- a/NEG/UI/Popup/IPopup.cs +++ b/NEG/UI/Popup/IPopup.cs @@ -20,7 +20,7 @@ namespace NEG.UI.Popup /// /// Close popup or mark as closed if not visible /// - /// if true hide visually, without firing callbacks to properly close - void Close(bool silence = false); + /// if true hide visually, without firing callbacks to properly close + void Close(bool silent = false); } } \ No newline at end of file diff --git a/NEG/UI/UnityUi/Buttons/ButtonReaction.cs b/NEG/UI/UnityUi/Buttons/ButtonReaction.cs new file mode 100644 index 0000000..9e8bf17 --- /dev/null +++ b/NEG/UI/UnityUi/Buttons/ButtonReaction.cs @@ -0,0 +1,15 @@ +using System; +using UnityEngine; + +namespace NEG.UI.UnityUi.Buttons +{ + [RequireComponent(typeof(BaseButton))] + public abstract class ButtonReaction : MonoBehaviour + { + private void Awake() => GetComponent().OnButtonPressed += OnClicked; + + private void OnDestroy() => GetComponent().OnButtonPressed -= OnClicked; + + protected abstract void OnClicked(); + } +} \ No newline at end of file diff --git a/NEG/UI/UnityUi/Buttons/ButtonReaction.cs.meta b/NEG/UI/UnityUi/Buttons/ButtonReaction.cs.meta new file mode 100644 index 0000000..1089ca5 --- /dev/null +++ b/NEG/UI/UnityUi/Buttons/ButtonReaction.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a9761128a04b49c2a26eddfabe70331f +timeCreated: 1675707257 \ No newline at end of file diff --git a/NEG/UI/UnityUi/Buttons/ChangeSceneButton.cs b/NEG/UI/UnityUi/Buttons/ChangeSceneButton.cs index d6ec44a..b6cc168 100644 --- a/NEG/UI/UnityUi/Buttons/ChangeSceneButton.cs +++ b/NEG/UI/UnityUi/Buttons/ChangeSceneButton.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -6,16 +7,14 @@ using UnityEngine.SceneManagement; namespace NEG.UI.UnityUi.Buttons { [RequireComponent(typeof(BaseButton))] - public class ChangeSceneButton : MonoBehaviour + public class ChangeSceneButton : ButtonReaction { [Header("Leave empty to use int value")] [SerializeField] private string sceneName; [SerializeField] private int sceneIndex; - - private void Awake() => GetComponent().OnButtonPressed += OnClicked; - private void OnClicked() + protected override void OnClicked() { if (string.IsNullOrEmpty(sceneName)) SceneManager.LoadScene(sceneIndex); diff --git a/NEG/UI/UnityUi/Buttons/CloseAllWindows.cs b/NEG/UI/UnityUi/Buttons/CloseAllWindows.cs index fb8954a..07fdc0c 100644 --- a/NEG/UI/UnityUi/Buttons/CloseAllWindows.cs +++ b/NEG/UI/UnityUi/Buttons/CloseAllWindows.cs @@ -2,10 +2,8 @@ namespace NEG.UI.UnityUi.Buttons { - [RequireComponent(typeof(BaseButton))] - public class CloseAllWindows : MonoBehaviour + public class CloseAllWindows : ButtonReaction { - private void Awake() => GetComponent().OnButtonPressed += OnClicked; - private void OnClicked() => UiManager.Instance.CurrentArea.CloseAllWindows(); + protected override void OnClicked() => UiManager.Instance.CurrentArea.CloseAllWindows(); } } \ No newline at end of file diff --git a/NEG/UI/UnityUi/Buttons/CloseWindow.cs b/NEG/UI/UnityUi/Buttons/CloseWindow.cs index 529b255..08d936e 100644 --- a/NEG/UI/UnityUi/Buttons/CloseWindow.cs +++ b/NEG/UI/UnityUi/Buttons/CloseWindow.cs @@ -6,12 +6,11 @@ using UnityEngine; namespace NEG.UI.UnityUi.Buttons { [RequireComponent(typeof(BaseButton))] - public class CloseWindow : MonoBehaviour + public class CloseWindow : ButtonReaction { [SerializeField] private MonoWindow windowToClose; - - private void Awake() => GetComponent().OnButtonPressed += OnClicked; - private void OnClicked() => windowToClose.Close(); + + protected override void OnClicked() => windowToClose.Close(); private void OnValidate() { diff --git a/NEG/UI/UnityUi/Buttons/OpenWindow.cs b/NEG/UI/UnityUi/Buttons/OpenWindow.cs index 701644b..08dd149 100644 --- a/NEG/UI/UnityUi/Buttons/OpenWindow.cs +++ b/NEG/UI/UnityUi/Buttons/OpenWindow.cs @@ -8,14 +8,12 @@ using NEG.UI.WindowSlot; namespace NEG.UI.UnityUi.Buttons { [RequireComponent(typeof(BaseButton))] - public class OpenWindow : MonoBehaviour + public class OpenWindow : ButtonReaction { [SerializeField] private MonoWindow window; [Header("Open on default area slot if empty")] [SerializeField] private MonoWindowSlot slot; - - private void Awake() => GetComponent().OnButtonPressed += OnClicked; - private void OnClicked() => window.Open(slot); + protected override void OnClicked() => window.Open(slot); } } \ No newline at end of file diff --git a/NEG/UI/UnityUi/CarouselList/CarouselList.cs b/NEG/UI/UnityUi/CarouselList/CarouselList.cs index 708c069..97760de 100644 --- a/NEG/UI/UnityUi/CarouselList/CarouselList.cs +++ b/NEG/UI/UnityUi/CarouselList/CarouselList.cs @@ -1,5 +1,6 @@ using JetBrains.Annotations; using NEG.UI.UnityUi.Buttons; +using System; using System.Collections.Generic; using TMPro; using UnityEngine; @@ -83,6 +84,12 @@ namespace NEG.UI.UnityUi prevButton.OnButtonPressed += SelectPrevOption; } + private void OnDestroy() + { + nextButton.OnButtonPressed -= SelectNextOption; + prevButton.OnButtonPressed -= SelectPrevOption; + } + private void ChangeOption(bool next) => SelectOption((CurrentOptionId + (next ? 1 : -1) + options.Count) % options.Count); } } \ No newline at end of file diff --git a/NEG/UI/UnityUi/Popup/MonoPopup.cs b/NEG/UI/UnityUi/Popup/MonoPopup.cs index 425edfb..eb51396 100644 --- a/NEG/UI/UnityUi/Popup/MonoPopup.cs +++ b/NEG/UI/UnityUi/Popup/MonoPopup.cs @@ -16,11 +16,11 @@ namespace NEG.UI.UnityUi.Popup gameObject.SetActive(true); } - public void Close(bool silence = false) + public void Close(bool silent = false) { gameObject.SetActive(false); - if(silence) + if(silent) return; OnPopupClosed?.Invoke(data);