using System; using System.Collections.Generic; using UnityEngine; public class UIManager : Singleton { private GameObject m_UIRoot; private Dictionary m_DicUI = new Dictionary(); 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(uiName); GameObject gameObject = UnityEngine.Object.Instantiate(@object as GameObject); gameObject.SetActive(false); if((gameObject.GetComponent(type) is BaseUI)) { baseUI= (gameObject.GetComponent(type) as BaseUI); } else { 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(@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(@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); } } }