123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class UIManager : Singleton<UIManager>
- {
- private GameObject m_UIRoot;
- private Dictionary<string, BaseUI> m_DicUI = new Dictionary<string, BaseUI>();
- private bool m_IsInit;
- public GameObject UIRoot
- {
- get
- {
- if (m_UIRoot == null)
- {
- m_UIRoot = GameObject.FindGameObjectWithTag("UIRoot_UGUI");
- }
- return m_UIRoot;
- }
- }
- public void Init()
- {
- if (m_IsInit)
- {
- return;
- }
- m_IsInit = true;
- }
- public void ShowUI(string uiName, Type type, object param = null)
- {
- if (null == UIRoot)
- {
- return;
- }
- BaseUI baseUI = null;
- m_DicUI.TryGetValue(uiName, out baseUI);
- if (null == baseUI)
- {
- UnityEngine.Object @object = ResMgr.Instance.Load("UI/" + uiName);
- GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(@object as GameObject);
- gameObject.SetActive(false);
- baseUI = (gameObject.AddComponent(type) as BaseUI);
- baseUI.UIName = uiName;
- baseUI.UIInit();
- baseUI.CacheTransform.SetParent(UIRoot.transform, false);
- m_DicUI[baseUI.UIName] = baseUI;
- }
- baseUI.Show(param);
- }
- public void ShowUI(string uiName, Type type, WarningUI.OnYesClick onYesClick, object param = null)
- {
- if (null == UIRoot)
- {
- return;
- }
- BaseUI baseUI = null;
- m_DicUI.TryGetValue(uiName, out baseUI);
- if (null == baseUI)
- {
- UnityEngine.Object @object = ResMgr.Instance.Load("UI/" + uiName);
- GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(@object as GameObject);
- gameObject.SetActive(false);
- baseUI = (gameObject.AddComponent(type) as BaseUI);
- baseUI.UIName = uiName;
- baseUI.UIInit();
- baseUI.CacheTransform.SetParent(UIRoot.transform, false);
- m_DicUI[baseUI.UIName] = baseUI;
- }
- baseUI.Show(onYesClick, param);
- }
- public void ShowUI(string uiName, Type type, WarningUI.OnYesClick onYesClick, WarningUI.OnNoClick onNoClick, object param = null)
- {
- if (null == UIRoot)
- {
- return;
- }
- BaseUI baseUI = null;
- m_DicUI.TryGetValue(uiName, out baseUI);
- if (null == baseUI)
- {
- UnityEngine.Object @object = ResMgr.Instance.Load("UI/" + uiName);
- GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(@object as GameObject);
- gameObject.SetActive(false);
- baseUI = (gameObject.AddComponent(type) as BaseUI);
- baseUI.UIName = uiName;
- baseUI.UIInit();
- baseUI.CacheTransform.SetParent(UIRoot.transform, false);
- m_DicUI[baseUI.UIName] = baseUI;
- }
- baseUI.Show(onYesClick, onNoClick, param);
- }
- public void HideUI(string uiName)
- {
- BaseUI baseUI = null;
- m_DicUI.TryGetValue(uiName, out baseUI);
- if (null != baseUI)
- {
- baseUI.Hide();
- }
- }
- public void DestroyUI(string uiName)
- {
- BaseUI baseUI = null;
- m_DicUI.TryGetValue(uiName, out baseUI);
- if (null != baseUI)
- {
- m_DicUI.Remove(baseUI.UIName);
- UnityEngine.Object.Destroy(baseUI.CacheGameObject);
- }
- }
- public bool IsUIOpen(string uiName)
- {
- BaseUI baseUI = null;
- m_DicUI.TryGetValue(uiName, out baseUI);
- return null != baseUI && baseUI.IsShow();
- }
- public BaseUI GetUI(string uiName)
- {
- BaseUI baseUI = null;
- m_DicUI.TryGetValue(uiName, out baseUI);
- if (null != baseUI)
- {
- return baseUI;
- }
- else
- {
- return null;
- }
- }
- public void ChangeCanvasPos()
- {
- if (OpenXRCamera.Instance.head != null)
- {
- m_UIRoot.transform.eulerAngles = new Vector3(0, OpenXRCamera.Instance.head.eulerAngles.y, 0);
- m_UIRoot.transform.position = OpenXRCamera.Instance.head.position + GameManager.Instance.Player.transform.forward + new Vector3(0, 0.3f, 0);
- }
- }
- public void ChangePos()
- {
- if (OpenXRCamera.Instance.head != null&&GameManager.Instance.Player.transform.position == OpenXRCamera.Instance.head.position)
- {
- m_UIRoot.transform.eulerAngles = new Vector3(0, OpenXRCamera.Instance.head.eulerAngles.y, 0);
- // Debug.Log(GameManager.Instance.Player.transform.position+" ########## "+ API_GSXR_Slam.GSXR_Get_Head().transform.forward);
- m_UIRoot.transform.position = GameManager.Instance.Player.transform.forward + new Vector3(0, -0.2f, 0.2f);
- }
- }
- }
|