Example #1
0
 //隐藏所有窗体的方法
 public void HideAllUI(bool isHideAboveUI, BaseUI baseUI)
 {
     if (isHideAboveUI)
     {
         //1、隐藏所有的窗体,不管是普通窗体还是保持在最前方的窗体,都需要全部隐藏
         foreach (KeyValuePair <E_UiId, BaseUI> uiItem in dicShowUI)
         {
             uiItem.Value.HideUI();
         }
         dicShowUI.Clear();
         //Debug.Log("清空dicShowUI");
     }
     else
     {
         //2、隐藏所有的窗体,但是不包含保持在最前方的窗体
         //缓存所有被隐藏的窗体
         List <E_UiId> list = new List <E_UiId>();
         foreach (KeyValuePair <E_UiId, BaseUI> uiItem in dicShowUI)
         {
             //如果不是保持在最前方的窗体
             if (uiItem.Value.uiType.uiRootType != E_UIRootType.KeepAbove)
             {
                 uiItem.Value.HideUI();
                 //存储上一个窗体的ID
                 beforeUiId = uiItem.Key;
                 // baseUI.BeforeUiId= uiItem.Key;
                 list.Add(uiItem.Key);
             }
         }
         for (int i = 0; i < list.Count; i++)
         {
             dicShowUI.Remove(list[i]);
         }
     }
 }
Example #2
0
        public static Type GetUIScriptType(E_UiId uiId)
        {
            Type scriptType = null;

            switch (uiId)
            {
            case E_UiId.NullUI:
                break;

            case E_UiId.MainUI:
                scriptType = typeof(MainUI);
                break;

            case E_UiId.LevelUI:
                scriptType = typeof(LevelUI);
                break;

            case E_UiId.PackUI:
                scriptType = typeof(PackUI);
                break;

            case E_UiId.InforUI:
                scriptType = typeof(InforUI);
                break;

            case E_UiId.PlayUI:
                scriptType = typeof(PlayUI);
                break;

            case E_UiId.ExitUI:
                scriptType = typeof(ExitUI);
                break;

            case E_UiId.LoadingUI:
                scriptType = typeof(LoadingUI);
                break;

            case E_UiId.NoticeUI:
                scriptType = typeof(NoticeUI);
                break;

            case E_UiId.SetUI:
                scriptType = typeof(SetUI);
                break;

            case E_UiId.LogoUI:
                scriptType = typeof(LogoUI);
                break;

            case E_UiId.ShopUI:
                scriptType = typeof(ShopUI);
                break;

            default:
                break;
            }
            return(scriptType);
        }
Example #3
0
 //供外界调用的,隐藏单个窗体的方法
 public void HideSingleUI(E_UiId uiId, Del_AfterHideUI del = null)
 {
     if (!dicShowUI.ContainsKey(uiId))
     {
         return;
     }
     dicShowUI[uiId].HideUI(del);
     dicShowUI.Remove(uiId);
 }
Example #4
0
 //供外界调用,销毁窗体
 public void DestroyUI(E_UiId uiId)
 {
     if (dicAllUI.ContainsKey(uiId))
     {
         //存在该窗体,去销毁
         Destroy(dicAllUI[uiId].gameObject);
         dicAllUI.Remove(uiId);
         //  Debug.Log("销毁窗体");
     }
 }
Example #5
0
 private BaseUI GetBaseUI(E_UiId UiId)
 {
     if (dicAllUI.ContainsKey(UiId))
     {
         return(dicAllUI[UiId]);
     }
     else
     {
         return(null);
     }
 }
Example #6
0
 public GameObject GetUIPanel(E_UiId uiId)
 {
     if (dicAllUI.ContainsKey(uiId))
     {
         return(dicAllUI[uiId].gameObject);
     }
     else
     {
         return(null);
     }
 }
Example #7
0
        //供外界调用的,显示窗体的方法
        public BaseUI ShowUI(E_UiId uiId, bool isSaveBeforeUiId = true)
        {
            if (uiId == E_UiId.NullUI)
            {
                uiId = E_UiId.MainUI;
            }
            BaseUI baseUI = JudgeShowUI(uiId);

            if (baseUI != null)
            {
                baseUI.ShowUI();
            }
            if (isSaveBeforeUiId)
            {
                baseUI.BeforeUiId = beforeUiId;
            }
            return(baseUI);
        }
Example #8
0
        private BaseUI JudgeShowUI(E_UiId uiId)
        {
            //判断将要显示的窗体是否已经正在显示了
            if (dicShowUI.ContainsKey(uiId))
            {
                //如果已经正在显示了,就不需要处理其他逻辑了
                return(null);
            }
            //判断窗体是否有加载过
            BaseUI baseUI = GetBaseUI(uiId);

            if (baseUI == null)
            {
                //说明这个窗体没显示过(没有加载过),要去动态加载
                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;
                    }
                    //判断这个窗体是属于哪个父节点的
                    Transform uiRoot = GetTheUIRoot(baseUI);
                    GameTool.AddChildToParent(uiRoot, willShowUI.transform);
                    willShowUI.GetComponent <RectTransform>().sizeDelta = Vector2.zero;
                    //这个窗体是第一次加载显示出来的,那么就需要缓存起来
                    dicAllUI.Add(uiId, baseUI);
                }
                else
                {
                    Debug.LogError("指定路径下面找不到对应的预制体");
                }
            }
            UpdateDicShowUIAndHideUI(baseUI);
            return(baseUI);
        }
Example #9
0
 //供外界调用,反向切换窗体的方法
 public void ReturnBeforeUI(E_UiId uiId)
 {
     ShowUI(uiId, false);
 }