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-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; }
|
|
|
|
|
|
|
|
|
|
private RectTransform _uiPanelRoot;
|
|
|
|
|
private RectTransform _uiPopRoot;
|
|
|
|
|
private RectTransform _hudRoot;
|
|
|
|
|
|
|
|
|
|
private Transform _uiRootTrans;
|
|
|
|
|
|
|
|
|
|
public override void Init()
|
|
|
|
|
{
|
|
|
|
|
//<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)
|
|
|
|
|
{
|
|
|
|
|
_hudRoot = new GameObject("HUDRoot").AddComponent<RectTransform>();
|
|
|
|
|
_hudRoot.SetParent(_uiRootTrans);
|
|
|
|
|
_hudRoot.anchoredPosition = Vector2.zero;
|
|
|
|
|
_hudRoot.anchorMin = Vector2.zero;
|
|
|
|
|
_hudRoot.anchorMax = Vector2.one;
|
|
|
|
|
_hudRoot.offsetMin = Vector2.zero;
|
|
|
|
|
_hudRoot.offsetMax = Vector2.zero;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_hudRoot = transform.Find("HUDRoot").GetComponent<RectTransform>();
|
|
|
|
|
_hudRoot.SetSiblingIndex(3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
panelGo.transform.SetParent(_hudRoot);
|
|
|
|
|
else
|
|
|
|
|
throw new Exception("UIManager.GetPanel() : panel is not a type of UIPanelBase, UIPopupBase or UIHudBase");
|
|
|
|
|
|
|
|
|
|
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-07 13:55:35 +00:00
|
|
|
|
}
|