/// <summary> /// 打开某个Ui /// </summary> /// <param name="panelName">Ui的名字</param> /// <param name="push">是否入栈</param> /// <param name="value">自定义数值</param> public void Open(string panelName, bool push = true, params object[] value) { if (m_uiDic.ContainsKey(panelName)) { m_uiDic[panelName].show(false, value); m_uiDic[panelName].transform.SetAsLastSibling(); m_uiDic[panelName].gameObject.SetActive(true); if (push) { if (m_uiStack.Count > 0) { if (m_uiDic.ContainsKey(m_uiStack[m_uiStack.Count - 1])) { m_uiDic[m_uiStack[m_uiStack.Count - 1]].gameObject.SetActive(false); } } m_uiStack.Add(panelName); } } else { if (ConfigManager.Instance.UIPanelConfigData.ContainsKey(panelName)) { UIPanelConfig uiData = ConfigManager.Instance.UIPanelConfigData[panelName]; if (uiData.Path != string.Empty) { GameObject go = Daemon.Instantiate(Resources.Load(uiData.Path) as GameObject); go.transform.SetParent(Canvas.transform, false); go.SetActive(false); UIBase ui = go.GetComponent <UIBase>(); m_uiDic.Add(panelName, ui); ui.show(true, value); ui.gameObject.SetActive(true); ui.transform.SetAsLastSibling(); if (push) { if (m_uiStack.Count > 0) { if (m_uiDic.ContainsKey(m_uiStack[m_uiStack.Count - 1])) { m_uiDic[m_uiStack[m_uiStack.Count - 1]].gameObject.SetActive(false); } } m_uiStack.Add(panelName); } } else { Debug.LogError("UIPath is empty!"); } } else { Debug.LogError("The UiPanel is not exist!"); } } }
private void OnEnable() { uiPanelConfig = (UIPanelConfig)target; }
/// <summary> /// 根据UIPanelName 打开面板 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name"></param> /// <param name="isTop">是否设置最顶层</param> /// <param name="paramArray"></param> /// <returns></returns> public T OpenWindow <T>(UIPanelName name, bool isTop = true, params object[] paramArray) where T : BaseView { if (!m_nameViewDic.ContainsKey(name)) { if (UIConfig.Instance.m_panelDic.ContainsKey(name)) { UIPanelConfig panelConfig = UIConfig.Instance.m_panelDic[name]; BaseView view = System.Activator.CreateInstance(Type.GetType(panelConfig.ClassName)) as BaseView; if (view != null) { var obj = ObjectsManager.Instance.InstantiateGameObj(panelConfig.Path, false, false); if (obj != null) { view.m_gameObj = obj; view.m_trans = view.m_gameObj.transform as RectTransform; if (panelConfig.Layer == UILayer.None || panelConfig.Layer == UILayer.NormalLayer) { view.m_trans.SetParent(m_normalLayerTr); } else if (panelConfig.Layer == UILayer.BaseLayer) { } else if (panelConfig.Layer == UILayer.TipsLayer) { } else if (panelConfig.Layer == UILayer.TopLayer) { } view.Init(); m_nameViewDic.Add(name, view); if (isTop) { view.m_trans.SetAsLastSibling(); } view.OnShow(); return(view as T); } else { Debug.LogError(string.Format("该路径{0}没有对应的prefab: {1}", panelConfig.Path, panelConfig.PrefabName)); } } else { Debug.LogError("无法创建View, 请检查类名"); } } else { Debug.LogError("不存在该Panel : " + name); } } else { BaseView temp = m_nameViewDic[name]; if (temp != null) { temp.OnShow(); } } return(null); }