mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Update UILoadMgr.cs
This commit is contained in:
@@ -7,8 +7,8 @@ namespace GameMain
|
|||||||
public static class UILoadMgr
|
public static class UILoadMgr
|
||||||
{
|
{
|
||||||
private static GameObject _uiLoad;
|
private static GameObject _uiLoad;
|
||||||
private static Dictionary<string, string> _uiList = new Dictionary<string, string>();
|
private static readonly Dictionary<string, string> UIList = new Dictionary<string, string>();
|
||||||
private static readonly Dictionary<string, UIBase> _uiMap = new Dictionary<string, UIBase>();
|
private static readonly Dictionary<string, UIBase> UIMap = new Dictionary<string, UIBase>();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化根节点
|
/// 初始化根节点
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -36,11 +36,11 @@ namespace GameMain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
RegisterUI();
|
RegisterUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RegisterUI()
|
private static void RegisterUI()
|
||||||
{
|
{
|
||||||
UIDefine.RegisterUI(_uiList);
|
UIDefine.RegisterUI(UIList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -53,16 +53,16 @@ namespace GameMain
|
|||||||
if (string.IsNullOrEmpty(uiInfo))
|
if (string.IsNullOrEmpty(uiInfo))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!_uiList.ContainsKey(uiInfo))
|
if (!UIList.ContainsKey(uiInfo))
|
||||||
{
|
{
|
||||||
Log.Error($"not define ui:{uiInfo}");
|
Log.Error($"not define ui:{uiInfo}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameObject ui = null;
|
GameObject ui = null;
|
||||||
if (!_uiMap.ContainsKey(uiInfo))
|
if (!UIMap.ContainsKey(uiInfo))
|
||||||
{
|
{
|
||||||
Object obj = Resources.Load(_uiList[uiInfo]);
|
Object obj = Resources.Load(UIList[uiInfo]);
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
{
|
{
|
||||||
ui = Object.Instantiate(obj) as GameObject;
|
ui = Object.Instantiate(obj) as GameObject;
|
||||||
@@ -76,16 +76,19 @@ namespace GameMain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UIBase compenent = ui.GetComponent<UIBase>();
|
if (ui != null)
|
||||||
if (compenent != null)
|
|
||||||
{
|
{
|
||||||
_uiMap.Add(uiInfo, compenent);
|
UIBase uiBase = ui.GetComponent<UIBase>();
|
||||||
}
|
if (uiBase != null)
|
||||||
|
{
|
||||||
|
UIMap.Add(uiInfo, uiBase);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_uiMap[uiInfo].gameObject.SetActive(true);
|
UIMap[uiInfo].gameObject.SetActive(true);
|
||||||
if (param != null)
|
if (param != null)
|
||||||
{
|
{
|
||||||
UIBase component = _uiMap[uiInfo].GetComponent<UIBase>();
|
UIBase component = UIMap[uiInfo].GetComponent<UIBase>();
|
||||||
if (component != null)
|
if (component != null)
|
||||||
{
|
{
|
||||||
component.OnEnter(param);
|
component.OnEnter(param);
|
||||||
@@ -95,22 +98,22 @@ namespace GameMain
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 隐藏ui对象
|
/// 隐藏ui对象
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="uiinfo">对应的ui</param>
|
/// <param name="uiName">对应的ui</param>
|
||||||
public static void Hide(string uiinfo)
|
public static void Hide(string uiName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(uiinfo))
|
if (string.IsNullOrEmpty(uiName))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_uiMap.ContainsKey(uiinfo))
|
if (!UIMap.ContainsKey(uiName))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_uiMap[uiinfo].gameObject.SetActive(false);
|
UIMap[uiName].gameObject.SetActive(false);
|
||||||
Object.DestroyImmediate(_uiMap[uiinfo].gameObject);
|
Object.DestroyImmediate(UIMap[uiName].gameObject);
|
||||||
_uiMap.Remove(uiinfo);
|
UIMap.Remove(uiName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -120,7 +123,7 @@ namespace GameMain
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static UIBase GetActiveUI(string ui)
|
public static UIBase GetActiveUI(string ui)
|
||||||
{
|
{
|
||||||
return _uiMap.ContainsKey(ui) ? _uiMap[ui] : null;
|
return UIMap.ContainsKey(ui) ? UIMap[ui] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -128,14 +131,14 @@ namespace GameMain
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void HideAll()
|
public static void HideAll()
|
||||||
{
|
{
|
||||||
foreach (var item in _uiMap)
|
foreach (var item in UIMap)
|
||||||
{
|
{
|
||||||
if (item.Value && item.Value.gameObject)
|
if (item.Value && item.Value.gameObject)
|
||||||
{
|
{
|
||||||
item.Value.gameObject.SetActive(false);
|
item.Value.gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_uiMap.Clear();
|
UIMap.Clear();
|
||||||
|
|
||||||
if (_uiLoad != null)
|
if (_uiLoad != null)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user