Frame/Assets/Scripts/UI/UIManager.cs

122 lines
2.6 KiB
C#

using System.Collections.Generic;
using System.Data;
using UnityEngine;
namespace Game
{
public class UIManager : ManagerBase, IUIManager
{
private Queue<IUI> _uis = new Queue<IUI>();
private Dictionary<UIType, IUI> _uiDic = new Dictionary<UIType, IUI>();
protected override void OnInit()
{
base.OnInit();
}
public T CreateUI<T>(UIType uiType) where T : UIBase
{
IUI ui = new UIBase(new GameObject());
//
ui.Init();
_uiDic.Add(uiType, ui);
return ui as T;
}
public IUI CreateUI(UIType uiType)
{
IUI ui = new UIBase(new GameObject());
//
ui.Init();
_uiDic.Add(uiType, ui);
return ui;
}
public T OpenUI<T>(UIType uiType) where T : UIBase
{
if (_uiDic.TryGetValue(uiType, out var ui))
{
_uis.Enqueue(ui);
ui.Open();
return (T)ui;
}
return null;
}
public IUI OpenUI(UIType uiType)
{
if (_uiDic.TryGetValue(uiType, out var ui))
{
_uis.Enqueue(ui);
ui.Open();
return ui;
}
return null;
}
public T GetUI<T>(UIType uiType) where T : UIBase
{
if (_uiDic.TryGetValue(uiType, out var ui))
{
return (T)ui;
}
return null;
}
public IUI GetUI(UIType uiType)
{
if (_uiDic.TryGetValue(uiType, out var ui))
{
return ui;
}
return null;
}
public T CloseUI<T>(UIType uiType) where T : UIBase
{
if (_uiDic.TryGetValue(uiType, out var ui))
{
ui.Close();
return (T)ui;
}
return null;
}
public IUI CloseUI(UIType uiType)
{
if (_uiDic.TryGetValue(uiType, out var ui))
{
ui.Close();
return ui;
}
return null;
}
public IUI CloseLast()
{
if (_uis.Count > 0)
{
var ui = _uis.Dequeue();
ui.Close();
return ui;
}
return null;
}
public void CloseAll()
{
while (_uis.Count > 0)
{
var ui = _uis.Dequeue();
ui.Close();
}
}
}
}