Exemplo n.º 1
0
        //判断窗体是否有显示过隐藏起来了,如果没有,就要去加载了
        private BaseUI JudgeShowUI(UIid uiId)
        {
            //判断要显示的窗体是不是正在显示
            if (dicShowUI.ContainsKey(uiId))
            {
                return(null);
            }
            //判断窗体是不是显示过了,然后被隐藏起来了
            BaseUI baseUI = GetBaseUI(uiId);

            if (baseUI == null)                           //说明将要显示的窗体还未被加载过
            {
                if (GameDefine.dicPath.ContainsKey(uiId)) //有该窗体的加载路径
                {
                    string     path  = GameDefine.dicPath[uiId];
                    GameObject theUI = Resources.Load <GameObject>(path);
                    if (theUI != null)
                    {
                        //把窗体生成出来
                        GameObject willShowUI = Instantiate(theUI);
                        //判断显示的窗体上面是否有挂载UI脚本
                        baseUI = willShowUI.GetComponent <BaseUI>();
                        if (baseUI == null)
                        {
                            //自动挂载对应的UI脚本
                            Type type = GameDefine.GetUIScriptType(uiId);
                            baseUI = willShowUI.AddComponent(type) as BaseUI;
                        }
                        GameTool.AddChildToParent(uiRoot, willShowUI.transform);
                        willShowUI.GetComponent <RectTransform>().sizeDelta          = Vector2.zero;
                        willShowUI.GetComponent <RectTransform>().anchoredPosition3D = Vector3.zero;
                        dicAllUI.Add(uiId, baseUI);
                    }
                    else
                    {
                        Debug.LogError("在路径" + path + "下面加载不到窗体,请查看该路径下面是否有窗体的预制体");
                    }
                }
                else//没有该窗体的加载路径
                {
                    Debug.LogError("没有该窗体的路径,请到GameDefine里面去添加");
                }
            }
            //更新字典并且隐藏需要隐藏的UI
            UpdateDicAndHideUI(baseUI);
            return(baseUI);
        }
Exemplo n.º 2
0
        //显示窗体的方法(isSaveBeforUIid是否要存储上一个跳转过来的窗体ID)
        public void ShowUI(UIid uiId, bool isSaveBeforUIid = true)
        {
            if (uiId == UIid.NullUI)
            {
                uiId = UIid.MainUI;
            }
            BaseUI baseUI = JudgeShowUI(uiId);

            if (baseUI != null)
            {
                baseUI.ShowUI();
                if (isSaveBeforUIid)
                {
                    baseUI.GetBeforUIid = beforeHidUIid;
                }
            }
        }