51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using NEG.UI.Popup;
|
|
using NEG.UI.UnityUi.Window;
|
|
using NEG.UI.UnityUi.WindowSlot;
|
|
using NEG.UI.Window;
|
|
using NEG.UI.WindowSlot;
|
|
using NegUtils.NEG.UI;
|
|
using System;
|
|
|
|
namespace NEG.UI.Area
|
|
{
|
|
public class MonoArea : MonoBehaviour, IArea, IControllable
|
|
{
|
|
public event Action<object> OnOpened;
|
|
public event Action OnClosed;
|
|
public event Action<IControllable.BackUsed> UseBack;
|
|
|
|
public IEnumerable<IWindowSlot> AvailableSlots => windowSlots;
|
|
public IWindowSlot DefaultWindowSlot => windowSlots[0];
|
|
|
|
[SerializeField] private bool setAsDefaultArea;
|
|
|
|
[SerializeField] private List<MonoWindowSlot> windowSlots;
|
|
|
|
public virtual void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled);
|
|
|
|
public virtual void OpenWindow(IWindow window, object data = null) => DefaultWindowSlot.AttachWindow(window, data);
|
|
|
|
protected virtual void Awake()
|
|
{
|
|
if (setAsDefaultArea)
|
|
UiManager.Instance.CurrentArea = this;
|
|
else
|
|
SetEnabled(false);
|
|
}
|
|
|
|
protected virtual void OnDestroy()
|
|
{
|
|
if (ReferenceEquals(UiManager.Instance.CurrentArea, this))
|
|
UiManager.Instance.CurrentArea = null;
|
|
}
|
|
|
|
|
|
public void FireOpenCallback(object data) => OnOpened?.Invoke(data);
|
|
|
|
public void FireOnClosed() => OnClosed?.Invoke();
|
|
|
|
public void FireUseBack(ref IControllable.BackUsed backUsed) => UseBack?.Invoke(backUsed);
|
|
}
|
|
} |