2023-11-07 13:55:35 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using OpenCVForUnity.CoreModule;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
2023-11-07 15:28:19 +00:00
|
|
|
|
using Yoga;
|
2023-11-14 17:01:48 +00:00
|
|
|
|
using OpenCVForUnityExample;
|
2023-11-07 13:55:35 +00:00
|
|
|
|
|
|
|
|
|
public class UIManager : MonoSingleton<UIManager>
|
|
|
|
|
{
|
|
|
|
|
private Dictionary<Type, UIBase> _panelDic = new Dictionary<Type, UIBase>();
|
|
|
|
|
private Stack<UIBase> _panelStack = new Stack<UIBase>();
|
|
|
|
|
|
|
|
|
|
public Camera UiCamera { get; set; }
|
|
|
|
|
|
2023-11-15 08:10:56 +00:00
|
|
|
|
private static bool _isInited = false;
|
|
|
|
|
public static bool IsInited { get => _isInited; private set => _isInited = value; }
|
|
|
|
|
|
2023-11-07 13:55:35 +00:00
|
|
|
|
private RectTransform _uiPanelRoot;
|
|
|
|
|
private RectTransform _uiPopRoot;
|
2023-11-14 17:01:48 +00:00
|
|
|
|
|
|
|
|
|
private HudUI _hud;
|
2023-11-07 13:55:35 +00:00
|
|
|
|
|
|
|
|
|
private Transform _uiRootTrans;
|
|
|
|
|
|
2023-11-14 17:01:48 +00:00
|
|
|
|
//hud ҳ<><D2B3>
|
|
|
|
|
private NotificationPopupUI _hintPannel;
|
|
|
|
|
|
2023-11-07 13:55:35 +00:00
|
|
|
|
public override void Init()
|
|
|
|
|
{
|
2023-11-15 08:10:56 +00:00
|
|
|
|
if (_isInited)
|
|
|
|
|
return;
|
2023-11-07 13:55:35 +00:00
|
|
|
|
//<2F><><EFBFBD>ҵ<EFBFBD>ǰscene<6E><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
UiCamera = Camera.main;
|
|
|
|
|
|
|
|
|
|
var canvases = GameObject.FindGameObjectsWithTag("UI");
|
|
|
|
|
GameObject canvas;
|
|
|
|
|
if (canvases.Length <= 0)
|
|
|
|
|
{
|
|
|
|
|
canvas = new GameObject("UICanvas");
|
|
|
|
|
canvas.AddComponent<Canvas>();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
canvas = canvases.ToList().Find(canvas => canvas.name == "UICanvas");
|
|
|
|
|
|
|
|
|
|
if (canvas == null)
|
|
|
|
|
{
|
|
|
|
|
canvas = new GameObject("UICanvas");
|
|
|
|
|
canvas.AddComponent<Canvas>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_uiRootTrans = canvas.transform;
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>Ȳ㼶 <20><><EFBFBD><EFBFBD> hud <20><><EFBFBD><EFBFBD> panel
|
|
|
|
|
//panel <20><><EFBFBD>ؽڵ<D8BD>
|
|
|
|
|
if (transform.Find("PanelRoot") == null)
|
|
|
|
|
{
|
|
|
|
|
_uiPanelRoot = new GameObject("PanelRoot").AddComponent<RectTransform>();
|
|
|
|
|
_uiPanelRoot.SetParent(_uiRootTrans);
|
|
|
|
|
_uiPanelRoot.anchoredPosition = Vector2.zero;
|
|
|
|
|
_uiPanelRoot.anchorMin = Vector2.zero;
|
|
|
|
|
_uiPanelRoot.anchorMax = Vector2.one;
|
|
|
|
|
_uiPanelRoot.offsetMin = Vector2.zero;
|
|
|
|
|
_uiPanelRoot.offsetMax = Vector2.zero;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_uiPanelRoot = transform.Find("PanelRoot").GetComponent<RectTransform>();
|
|
|
|
|
|
|
|
|
|
_uiPanelRoot.SetSiblingIndex(1);
|
|
|
|
|
|
|
|
|
|
//pop <20><><EFBFBD>ؽڵ<D8BD>
|
|
|
|
|
if (transform.Find("PopRoot") == null)
|
|
|
|
|
{
|
|
|
|
|
_uiPopRoot = new GameObject("PopRoot").AddComponent<RectTransform>();
|
|
|
|
|
_uiPopRoot.SetParent(_uiRootTrans);
|
|
|
|
|
_uiPopRoot.anchoredPosition = Vector2.zero;
|
|
|
|
|
_uiPopRoot.anchorMin = Vector2.zero;
|
|
|
|
|
_uiPopRoot.anchorMax = Vector2.one;
|
|
|
|
|
_uiPopRoot.offsetMin = Vector2.zero;
|
|
|
|
|
_uiPopRoot.offsetMax = Vector2.zero;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_uiPopRoot = transform.Find("PopRoot").GetComponent<RectTransform>();
|
|
|
|
|
|
|
|
|
|
_uiPopRoot.SetSiblingIndex(2);
|
|
|
|
|
|
|
|
|
|
//hud <20><><EFBFBD>ؽڵ<D8BD>
|
|
|
|
|
if (transform.Find("HUDRoot") == null)
|
|
|
|
|
{
|
2023-11-14 17:01:48 +00:00
|
|
|
|
_hud = GetPanel<HudUI>();
|
|
|
|
|
_hud.transform.SetParent(_uiRootTrans);
|
|
|
|
|
var rect = _hud.transform.GetComponent<RectTransform>();
|
|
|
|
|
rect.anchorMin = Vector2.zero;
|
|
|
|
|
rect.anchorMax = Vector2.one;
|
|
|
|
|
rect.pivot = new Vector2(0.5f, 0.5f);
|
|
|
|
|
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Screen.width);
|
|
|
|
|
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Screen.height);
|
|
|
|
|
rect.offsetMin = Vector2.zero;
|
|
|
|
|
rect.offsetMax = Vector2.zero;
|
|
|
|
|
_hud.Init(null);
|
2023-11-07 13:55:35 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2023-11-14 17:01:48 +00:00
|
|
|
|
_hud = transform.Find("HUDRoot").GetComponent<HudUI>();
|
|
|
|
|
_hud.transform.SetSiblingIndex(3);
|
2023-11-15 08:10:56 +00:00
|
|
|
|
_isInited = true;
|
2023-11-07 13:55:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-15 08:10:56 +00:00
|
|
|
|
public void LoadReset()
|
|
|
|
|
{
|
|
|
|
|
_isInited = false;
|
|
|
|
|
Init();
|
|
|
|
|
}
|
2023-11-07 13:55:35 +00:00
|
|
|
|
private T GetPanel<T>() where T : UIBase
|
|
|
|
|
{
|
|
|
|
|
Type type = typeof(T);
|
|
|
|
|
//<2F><EFBFBD><DEBB>棬<EFBFBD><E6A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>Panel<65>ļ<EFBFBD>
|
|
|
|
|
if (_panelDic.TryGetValue(type, out var panel))
|
|
|
|
|
{
|
|
|
|
|
if (panel != null)
|
|
|
|
|
_panelDic[type].Destroy();
|
|
|
|
|
_panelDic.Remove(type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string path = UILoadConfig.GetPath(type.FullName);
|
|
|
|
|
GameObject panelGo = Instantiate(Resources.Load<GameObject>(path));
|
|
|
|
|
panel = panelGo.GetComponent<T>();
|
|
|
|
|
if (panel is UIPanelBase)
|
|
|
|
|
panelGo.transform.SetParent(_uiPanelRoot);
|
|
|
|
|
else if (panel is UIPopupBase)
|
|
|
|
|
panelGo.transform.SetParent(_uiPopRoot);
|
|
|
|
|
else if (panel is UIHudBase)
|
2023-11-14 17:01:48 +00:00
|
|
|
|
{
|
|
|
|
|
panelGo.transform.localPosition = Vector3.zero;
|
|
|
|
|
//hudҳ<64>治<EFBFBD><E6B2BB>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
|
|
|
|
|
return panel as T;
|
|
|
|
|
}
|
2023-11-07 13:55:35 +00:00
|
|
|
|
else
|
2023-11-14 17:01:48 +00:00
|
|
|
|
throw new Exception("UIManager.GetPanel() : panel is not a type of UIPanelBase, UIPopupBase");
|
2023-11-07 13:55:35 +00:00
|
|
|
|
|
|
|
|
|
panelGo.transform.localPosition = Vector3.zero;
|
|
|
|
|
|
|
|
|
|
_panelDic.Add(type, panel);
|
|
|
|
|
return panel as T;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowPanel<T>(params object[] args) where T : UIBase
|
|
|
|
|
{
|
|
|
|
|
T panel = GetPanel<T>();
|
|
|
|
|
panel.Init(args);
|
|
|
|
|
panel.gameObject.SetActive(true);
|
|
|
|
|
panel.OnEnter();
|
|
|
|
|
_panelStack.Push(panel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowPanel<T>(bool hideCurrentPage, params object[] args) where T : UIBase
|
|
|
|
|
{
|
|
|
|
|
if (hideCurrentPage)
|
|
|
|
|
{
|
|
|
|
|
if (_panelStack.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var topPanel = _panelStack.Peek();
|
|
|
|
|
topPanel.OnPause();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShowPanel<T>(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearPanel()
|
|
|
|
|
{
|
|
|
|
|
foreach (var panel in _panelDic.Values)
|
|
|
|
|
{
|
|
|
|
|
panel.OnExit();
|
|
|
|
|
}
|
|
|
|
|
_panelStack.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PushPanel<T>() where T : UIBase
|
|
|
|
|
{
|
|
|
|
|
if (_panelStack.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var topPanel = _panelStack.Peek();
|
|
|
|
|
topPanel.OnPause();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var panel = GetPanel<T>();
|
|
|
|
|
_panelStack.Push(panel);
|
|
|
|
|
panel.OnEnter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PopPanel()
|
|
|
|
|
{
|
|
|
|
|
if (_panelStack.Count <= 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UIBase topPanel = _panelStack.Pop();
|
|
|
|
|
topPanel.OnHide();
|
|
|
|
|
topPanel.OnExit();
|
|
|
|
|
|
|
|
|
|
if (_panelStack.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
UIBase nextPanel = _panelStack.Peek();
|
|
|
|
|
nextPanel.OnResume();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CloseCurrent()
|
|
|
|
|
{
|
|
|
|
|
PopPanel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadScene()
|
|
|
|
|
{
|
|
|
|
|
EnableScreenMask();
|
|
|
|
|
var op = SceneManager.LoadSceneAsync("YogaMain");
|
|
|
|
|
op.completed += (operation) =>
|
|
|
|
|
{
|
|
|
|
|
DisableScreenMask();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EnableScreenMask()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DisableScreenMask()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2023-11-07 15:28:19 +00:00
|
|
|
|
|
|
|
|
|
public void CloseUI(UIBase targetUI)
|
|
|
|
|
{
|
|
|
|
|
if (_panelStack.Count <= 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
targetUI.OnHide();
|
|
|
|
|
targetUI.OnExit();
|
|
|
|
|
//<2F><>ջ<EFBFBD><D5BB><EFBFBD>Ƴ<EFBFBD>
|
|
|
|
|
_panelStack = new Stack<UIBase>(_panelStack.Where(ui => ui != targetUI));
|
|
|
|
|
//<2F><EFBFBD><F2BFAAB6><EFBFBD>ҳ<EFBFBD><D2B3>
|
|
|
|
|
if (_panelStack.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
UIBase nextPanel = _panelStack.Peek();
|
|
|
|
|
nextPanel.OnResume();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-14 17:01:48 +00:00
|
|
|
|
|
|
|
|
|
//hud ҳ<><D2B3>
|
|
|
|
|
public void ShowHint(string title, string content)
|
|
|
|
|
{
|
|
|
|
|
EventManager.Instance.Dispatch(YogaEventType.ShowHint, title, content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowMsgBox(string title, string content)
|
|
|
|
|
{
|
|
|
|
|
EventManager.Instance.Dispatch(YogaEventType.ShowMessage, title, content);
|
|
|
|
|
}
|
2023-11-07 13:55:35 +00:00
|
|
|
|
}
|
2023-11-14 17:01:48 +00:00
|
|
|
|
|