2025-10-13 07:35:57 +08:00
|
|
|
|
using System;
|
2025-09-29 07:45:07 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using YooAsset;
|
|
|
|
|
|
|
2025-09-29 11:03:26 +08:00
|
|
|
|
public class UIManager : Singleton<UIManager>
|
2025-09-29 07:45:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
Dictionary<string, UIBaseWindow> openedWindows = new Dictionary<string, UIBaseWindow>();
|
2025-10-09 07:51:05 +08:00
|
|
|
|
public void Init()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-29 07:45:07 +08:00
|
|
|
|
public void ShowWindow<T>(string windowName,Action<T> onShow = null) where T : UIBaseWindow
|
|
|
|
|
|
{
|
|
|
|
|
|
if (openedWindows.ContainsKey(windowName))
|
|
|
|
|
|
{
|
|
|
|
|
|
var window = openedWindows[windowName] as T;
|
|
|
|
|
|
window.Show();
|
|
|
|
|
|
onShow?.Invoke(window);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
YooAssets.LoadAssetAsync<GameObject>(windowName).Completed += handle =>
|
|
|
|
|
|
{
|
2025-09-29 11:03:26 +08:00
|
|
|
|
GameObject go = GameObject.Instantiate((GameObject)handle.AssetObject, GameManager.Inst.MainUICanvas.transform);
|
2025-09-29 07:45:07 +08:00
|
|
|
|
var window = go.GetComponent<T>();
|
|
|
|
|
|
window.Show();
|
2025-09-29 11:03:26 +08:00
|
|
|
|
openedWindows[windowName] = window;
|
2025-09-29 07:45:07 +08:00
|
|
|
|
onShow?.Invoke(window);
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void HideWindow(string windowName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (openedWindows.ContainsKey(windowName))
|
|
|
|
|
|
{
|
|
|
|
|
|
openedWindows[windowName].Hide();
|
|
|
|
|
|
}
|
2025-09-29 11:03:26 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-10-09 07:51:05 +08:00
|
|
|
|
Debug.Log("未找到该名字窗口,使用窗口类名试试");
|
2025-09-29 11:03:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public bool CheckShow(string windowName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (openedWindows.ContainsKey(windowName))
|
|
|
|
|
|
{
|
|
|
|
|
|
return openedWindows[windowName].gameObject.activeSelf;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2025-09-29 07:45:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|