132 lines
2.9 KiB
C#
132 lines
2.9 KiB
C#
using PimDeWitte.UnityMainThreadDispatcher;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class UIManager : SingleTon<UIManager>
|
|
{
|
|
private Dictionary<UIType, UIBase> uiDic = new Dictionary<UIType, UIBase>();
|
|
|
|
public GameData GameData { get; private set; }
|
|
|
|
public void Init()
|
|
{
|
|
GameData = DataManager.Instance.GetGameData();
|
|
EventCenter.dispatcher.AddListener(MsgType.OnGetCode, Show1);
|
|
}
|
|
|
|
private void Show1(Message evt)
|
|
{
|
|
ShowHint("Âö²«¼ì²é - è㶯Âö - ¼ì²é");
|
|
}
|
|
|
|
public UIBase GetUIBase(UIType uIType)
|
|
{
|
|
if (uiDic.ContainsKey(uIType))
|
|
{
|
|
return uiDic[uIType].gameObject.GetComponent<UIBase>();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void ShowHint(string str)
|
|
{
|
|
if (uiDic.ContainsKey(UIType.UIHint))
|
|
{
|
|
if (uiDic[UIType.UIHint] != null)
|
|
{
|
|
UnityMainThreadDispatcher.Instance().Enqueue(() =>
|
|
{
|
|
UIHint ui = (UIHint)uiDic[UIType.UIHint];
|
|
ui.open();
|
|
ui.Init(str);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
public void HideHint()
|
|
{
|
|
if (uiDic.ContainsKey(UIType.UIHint))
|
|
{
|
|
if (uiDic[UIType.UIHint] != null)
|
|
{
|
|
UIHint ui = (UIHint)uiDic[UIType.UIHint];
|
|
ui.close();
|
|
}
|
|
}
|
|
}
|
|
|
|
public UIBase OpenUI(UIType uIType)
|
|
{
|
|
if (uiDic.ContainsKey(uIType))
|
|
{
|
|
uiDic[uIType]?.Open();
|
|
}
|
|
else
|
|
{
|
|
GameObject Prefab = (GameObject)Resources.Load("UIPrefabs/" + uIType.ToString());
|
|
var newUI = GameObject.Instantiate(Prefab, GameData.mainCanvas.transform);
|
|
uiDic.Add(uIType, newUI.GetComponent<UIBase>());
|
|
}
|
|
return uiDic[uIType];
|
|
}
|
|
|
|
public void CloseUI(UIType uIType)
|
|
{
|
|
if (uiDic.ContainsKey(uIType))
|
|
{
|
|
uiDic[uIType]?.Close();
|
|
}
|
|
}
|
|
|
|
public bool isShow(UIType uIType)
|
|
{
|
|
if (uiDic.ContainsKey(uIType))
|
|
{
|
|
return uiDic[uIType].gameObject.activeSelf;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void ShowMainUI()
|
|
{
|
|
GameData.mainUI.Open();
|
|
}
|
|
public void CloseMainUI()
|
|
{
|
|
GameData.mainUI.Close();
|
|
|
|
}
|
|
|
|
public void CloseAllUI()
|
|
{
|
|
foreach (var ui in uiDic.Values)
|
|
{
|
|
if (ui.isTools != 1)
|
|
{
|
|
ui.Close();
|
|
}
|
|
}
|
|
CloseMainUI();
|
|
}
|
|
|
|
public void ShowAllUI()
|
|
{
|
|
foreach (var ui in uiDic.Values)
|
|
{
|
|
ui.Open();
|
|
}
|
|
ShowMainUI();
|
|
}
|
|
|
|
public void DestoryUI(UIType uIType)
|
|
{
|
|
if (uiDic.ContainsKey(uIType))
|
|
{
|
|
uiDic[uIType].Destroy();
|
|
uiDic.Remove(uIType);
|
|
}
|
|
}
|
|
} |