/// <summary> /// 添加面板 /// </summary> /// <param name="panelName"></param> /// <returns></returns> public bool addPanel(string panelName) { //已有,返回添加失败 if (Panels.ContainsKey(panelName)) { return(false); } //没有,实例化一个 GameObject panel = ResourceManager.getInstance().getGameObject(panelName); if (panel == null) { return(false); } //取得面板类 UIPanelBase uiPanelBase = panel.GetComponent <UIPanelBase>(); if (uiPanelBase == null) { return(false); } //设置面板名 uiPanelBase.panelName = panelName; if (canvas == null) { canvas = GameObject.Find("Canvas"); } //实例化canvas if (canvas == null) { canvas = ResourceManager.getInstance().getGameObject("Canvas"); canvas.name = "Canvas"; } //设置canvas为父容器 uiPanelBase.transform.SetParent(canvas.transform, false); //添加到canvas里 RectTransform rt = (uiPanelBase.gameObject.transform as RectTransform); rt.anchoredPosition = Vector2.zero; uiPanelBase.gameObject.transform.localScale = Vector3.one; //不可见 panel.gameObject.SetActive(false); //添加到容器 Panels.Add(panelName, uiPanelBase); //返回添加成功 return(true); }
/// <summary> /// 添加面板 /// </summary> /// <param name="panel"></param> /// <returns></returns> public bool addPanel(UIPanelBase panel) { //不存在,返回失败 if (panel == null) { return false; } //已经存在返回添加失败 if (Panels.ContainsKey(panel.panelName)) { return false; } //不可见 panel.gameObject.SetActive(false); //添加到容器 Panels.Add(panel.panelName, panel); //返回添加成功 return true; }
/// <summary> /// 添加面板 /// </summary> /// <param name="panel"></param> /// <returns></returns> public bool addPanel(UIPanelBase panel) { //不存在,返回失败 if (panel == null) { return(false); } //已经存在返回添加失败 if (Panels.ContainsKey(panel.panelName)) { return(false); } //不可见 panel.gameObject.SetActive(false); //添加到容器 Panels.Add(panel.panelName, panel); //返回添加成功 return(true); }