diff --git a/NEG/UI/UiManager.cs b/NEG/UI/UiManager.cs index 76a4921..1fdac69 100644 --- a/NEG/UI/UiManager.cs +++ b/NEG/UI/UiManager.cs @@ -19,17 +19,11 @@ namespace NEG.UI get => currentArea; set { - if (value == null) - { - Debug.LogError("CurrentArea can't be null"); - return; - } - currentArea?.SetEnabled(false); currentArea = value; - currentArea.SetEnabled(true); + currentArea?.SetEnabled(true); } } @@ -51,6 +45,7 @@ namespace NEG.UI } Instance = this; + CurrentArea = startArea; } diff --git a/NEG/UI/UnityUi/Area/MonoArea.cs b/NEG/UI/UnityUi/Area/MonoArea.cs index 7691c08..0a2ade2 100644 --- a/NEG/UI/UnityUi/Area/MonoArea.cs +++ b/NEG/UI/UnityUi/Area/MonoArea.cs @@ -4,6 +4,7 @@ using NEG.UI.Popup; using NEG.UI.UnityUi.WindowSlot; using NEG.UI.Window; using NEG.UI.WindowSlot; +using System; namespace NEG.UI.Area { @@ -11,20 +12,31 @@ namespace NEG.UI.Area { public IEnumerable AvailableSlots => windowSlots; public IWindowSlot DefaultWindowSlot => windowSlots[0]; - public IEnumerable CurrentWindows { get; } + + [SerializeField] private bool setAsDefaultArea; [SerializeField] private List windowSlots; [SerializeField] private Queue currentPopups = new(); - public void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled); + public virtual void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled); - public void OpenWindow(IWindow window, object data = null) + public virtual void OpenWindow(IWindow window, object data = null) { DefaultWindowSlot.AttachWindow(window); window.SetData(data); } - + protected virtual void Awake() + { + if (setAsDefaultArea) + UiManager.Instance.CurrentArea = this; + } + + protected virtual void OnDestroy() + { + if (ReferenceEquals(UiManager.Instance.CurrentArea, this)) + UiManager.Instance.CurrentArea = null; + } } } \ No newline at end of file