2025-09-29 07:45:07 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
|
Transform uiRoot;
|
|
|
|
|
|
Dictionary<string, UIBaseWindow> openedWindows = new Dictionary<string, UIBaseWindow>();
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("δ<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>ڣ<EFBFBD>ʹ<EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|