/// <summary> /// 隐藏 Panel /// </summary> /// <param name="name"></param> public static void Hide(string name) { //没有打开 if (!panels.ContainsKey(name)) { return; } BasePanel panel = panels[name]; //OnHide panel.OnHide(); //隐藏物体 canvas.Find(panels[name].layer.ToString()).Find(name + "(Clone)").gameObject.SetActive(false); panels[name].enabled = false; }
private BasePanel GetPanel(UIPanelType uiPanelType) { BasePanel panel = null; if (!panelDic.ContainsKey(uiPanelType)) { string path = "UiPanels/" + uiPanelType.ToString(); GameObject g = Resources.Load(path) as GameObject; GameObject go = Instantiate(g); panel = go.GetComponent <BasePanel>(); panel.transform.SetParent(this.transform); panel.SetActiveUI(false); panelDic.Add(uiPanelType, panel); return(panel); } panel = panelDic[uiPanelType]; return(panel); }
public void PopPanel() { if (panelStack.Count <= 0) { return; } BasePanel topPanel = panelStack.Pop(); topPanel.SetActiveUI(false); if (panelStack.Count <= 0) { return; } BasePanel topPanel2 = panelStack.Peek(); topPanel.SetActiveUI(true); }
/// <summary> /// 关闭Panel /// </summary> /// <typeparam name="T">Panel的类型</typeparam> /// <param name="para">Panel 的名字</param> public static void Close(string name) { //没有打开 if (!panels.ContainsKey(name)) { return; } BasePanel panel = panels[name]; //OnClose panel.OnClose(); panel.OnRemoveListener(); //列表 panels.Remove(name); //销毁 GameObject.Destroy(panel.skin); Component.Destroy(panel); }
//出栈 public void PopPanel(Animation anim, float time) { if (panelStack == null) { panelStack = new Stack <BasePanel>(); } if (panelStack.Count <= 0) { Debug.Log("没有界面"); return; } //退出栈顶面板 BasePanel topPanel = panelStack.Pop(); //恢复上一个面板放到动画里 播放完成在恢复上一个Panel的焦点 PopAnim(anim, topPanel.transform, time); topPanel.OnExit(); }
//入栈 public void PushPanel(string panelType, Animation anim, float time) { if (panelStack == null) { panelStack = new Stack <BasePanel>(); } //停止上一个界面 if (panelStack.Count > 0) { BasePanel topPanel = panelStack.Peek(); topPanel.OnPause(); } BasePanel panel = GetPanel(panelType); panel.OnEnter(); panelStack.Push(panel); PushAnim(anim, panel.transform, 0.2f); panel.gameObject.SetActive(true); }
private Dictionary <string, BasePanel> panelDic; //存储panel信息 /// <summary> /// 得到Panel /// </summary> public BasePanel GetPanel(string paneltype) { //如果==null if (panelDic == null) { panelDic = new Dictionary <string, BasePanel>(); } BasePanel panel = null;//根据key找到值 try { panelDic.TryGetValue(paneltype, out panel); } catch (Exception e) { //不知是否有空值异常 Debug.Log(e.Message); } //空就去Json表字典找到 if (panel == null) { string path = null; try { panelPathDic.TryGetValue(paneltype, out path); } catch (Exception e) { //空异常 Debug.Log(e.Message); } GameObject panelGo = ObjectPool.GetInstance().GetObj(path.Split('/')[1], CanvasTransform); panel = panelGo.GetComponent <BasePanel>(); panelDic.Add(paneltype, panel);//放入字典 } panel.gameObject.SetActive(true); return(panel); }
/// <summary> /// 打开Panel /// </summary> /// <typeparam name="T">Panel的类型</typeparam> /// <param name="para">Panel 的名字</param> public static void Open <T>(params object[] para) where T : BasePanel { //已经存在 string name = typeof(T).ToString(); if (panels.ContainsKey(name)) { Transform panelType = canvas.Find(panels[name].layer.ToString()); //已经显示 if (panelType.Find(name + "(Clone)").gameObject.activeInHierarchy&& panels[name].enabled) { //组件 BasePanel thisPanel = root.gameObject.GetComponent <T>(); thisPanel.UpdataPara(para); return; } //正在隐藏 else { panelType.Find(name + "(Clone)").gameObject.SetActive(true); panels[name].enabled = true; return; } } //组件 BasePanel panel = root.gameObject.AddComponent <T>(); panel.OnInit(); panel.Init(); //父容器 Transform layer = layers[panel.layer]; panel.skin.transform.SetParent(layer, false); //列表 panels.Add(name, panel); //OnShow panel.OnShow(para); panel.OnAddListener(); }