Esempio n. 1
0
    public BaseView JudgeShowUI(EUiId uiId)
    {
        //First、FirstOrDefault的区别在于:当没有元素满足条件时,一个抛出异常,一个返回默认值。
        BaseView baseUI = _dicAllUI.FirstOrDefault(t => t.Key == uiId).Value;

        //如果baseui在字典里面没有查找到,说明该窗体还没有加载过
        if (baseUI == null)
        {
            Type     type  = Type.GetType(uiId.ToString());
            BaseView theUI = Instantiate(Resources.Load <GameObject>("Prefabs/UI/" + uiId.ToString())).AddComponent(type) as BaseView;
            if (theUI != null)
            {
                Transform theRoot = GetUIRoot(theUI);
                GlobalTools.AddChildToParent(theRoot, theUI.transform);
                _dicAllUI[uiId] = theUI;
                baseUI          = theUI;
            }
            else
            {
                Debug.LogError("Load UI Null");
            }
        }
        UpDateStack(baseUI);
        return(baseUI);
    }
Esempio n. 2
0
 //点击返回按钮
 public void ClickReturn()
 {
     //说明没有反向切换的信息
     if (_stackReturnInfor.Count == 0)
     {
         if (_currentUI.beforeUiId != EUiId.NullUI)
         {
             HideTheUI(_currentUI.uiId, delegate { ShowUI(_currentUI.beforeUiId); });
         }
     }
     //说明有反向切换信息
     else
     {
         UIReturnInfor uiReturnInfor = _stackReturnInfor.Peek();
         if (uiReturnInfor != null)
         {
             //获得当前窗体的ui
             EUiId theId = uiReturnInfor._willBeShowUI.uiId;
             if (_dicShownUI.ContainsKey(theId))
             {
                 HideTheUI(theId, delegate
                 {
                     BaseView baseUI          = _dicAllUI.FirstOrDefault(t => t.Key == uiReturnInfor._listReturn[0]).Value;
                     _dicShownUI[baseUI.uiId] = baseUI;
                     baseUI.gameObject.SetActive(true);
                     _currentUI = baseUI;
                     //pop是把栈顶元素删除
                     _stackReturnInfor.Pop();
                 });
             }
         }
     }
 }
Esempio n. 3
0
    public void hideUI(EUiId id, Action a = null) //隐藏UI,传入ID和需要做的事情
    {
        if (!dicShowUI.ContainsKey(id))           //正在显示的容器中没有此ID
        {
            return;
        }
        if (a == null)            //隐藏UI的时候不需要做别的事情
        {
            dicShowUI[id].hide(); //直接隐藏
            dicShowUI.Remove(id); //从显示列表中删除
        }
        else//隐藏窗体之后需要做的事情
        {
            a += () => { dicShowUI.Remove(id); };
            dicShowUI[id].hide(a);
        }

        //查看当前面板是否隐藏了其他所有的面板,如果是,那么打开主面板 add zl 2017.08.24
        if (dicAllUI[id].showMode == EUIShowMode.hideAll)
        {
            foreach (KeyValuePair <EUiId, UIBasePanel> AboveUI in dicAllUI)
            {
                if (AboveUI.Value.IsKeepAbove)
                {
                    dicShowUI[AboveUI.Key] = AboveUI.Value;
                    AboveUI.Value.show();
                }
            }
        }
    }
Esempio n. 4
0
    public Transform transUIRoot;                                                             //UI根节点

    public void delUI(EUiId id)
    {
        if (dicShowUI.ContainsKey(id))
        {
            dicShowUI.Remove(id);
        }
    }
Esempio n. 5
0
    public BaseView ShowUI(EUiId uiId, bool isABLoad = true, string tips = "")
    {
        BaseView baseUI = JudgeShowUI(uiId);

        if (baseUI != null)
        {
            baseUI.ShowUI();

            dicShownUI[uiId] = baseUI;
            if (baseUI.isResetReturnUIInfor)
            {
                //重置反向切换的信息(当显示的是Mainui的时候就需要重置)
                ClearStackReturnInfor();
            }
            if (uiId == EUiId.ErrorBoxView)
            {
                (baseUI as ErrorBoxView).SetContent(tips);
            }
            if (baseUI.rootType == EUIRootType.Normal)
            {
                //beforeUI = currentUI;
                currentUI = baseUI;
            }
            Debug.Log("显示:" + uiId);
            return(baseUI);
        }
        else
        {
            return(null);
        }
    }
Esempio n. 6
0
 public void AssignViewRender(EUiId eUiId)
 {
     //先判断窗体是不是正在显示(已经显出)
     if (dicShownUI.ContainsKey(eUiId))//已经显示出来了
     {
         dicShownUI[eUiId].Render();
     }
 }
Esempio n. 7
0
 public static string getUiIdPath(EUiId id)
 {
     if (dicPath.ContainsKey(id))
     {
         return(dicPath[id]);
     }
     return(null);
 }
Esempio n. 8
0
 private void RemoveUiId(EUiId uiId)
 {
     if (dicShowUI.ContainsKey(uiId))
     {
         dicShowUI.Remove(uiId);
     }
     if (dicAllUI.ContainsKey(uiId))
     {
         dicAllUI.Remove(uiId);
     }
 }
Esempio n. 9
0
 private Type GetTypeByUiId(EUiId eUiId)
 {
     foreach (var item in baseUiSubTypes)
     {
         if (item.Name == Enum.GetName(eUiId.GetType(), eUiId))
         {
             return(item);
         }
     }
     return(null);
 }
Esempio n. 10
0
 //判断窗体是否有显示过
 private BaseUI GetBaseUI(EUiId uiId)
 {
     if (dicAllUI.ContainsKey(uiId))
     {
         return(dicAllUI[uiId]);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 11
0
 /// <summary>
 /// 从容器中获取需要显示的UI
 /// </summary>
 /// <param name="id">传入进来的ID</param>
 /// <returns></returns>
 public UIBasePanel getUI(EUiId id)
 {
     if (dicAllUI.ContainsKey(id))
     {
         return(dicAllUI[id]);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 12
0
 //判断当前ui是否被加载过
 public BaseView GetBaseUI(EUiId uiId)
 {
     if (dicAllUI.ContainsKey(uiId))
     {
         return(dicAllUI[uiId]);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 13
0
    public void showUI(EUiId id)
    {
        //1:加载当前UI
        if (dicShowUI.ContainsKey(id))//当前UI已经在显示列表中了,就直接返回
        {
            return;
        }
        UIBasePanel ui = getUI(id);               //通过ID获取需要显示的UI,从dicAllUI容器中获取,得到的是隐藏的UIPanel

        if (ui == null)                           //如果在dicAllUI容器中没有此UI,就从资源中读取ui预制体
        {
            string path = UIPath.getUiIdPath(id); //通过ID,获取对应的路径
            if (!string.IsNullOrEmpty(path))
            {
                GameObject prefab = Resources.Load <GameObject>(path);//加载资源
                //获取UI原始数据
                Vector2 offMin    = prefab.GetComponent <RectTransform>().offsetMin;
                Vector2 offMax    = prefab.GetComponent <RectTransform>().offsetMax;
                Vector2 anchorMin = prefab.GetComponent <RectTransform>().anchorMin;
                Vector2 anchorMax = prefab.GetComponent <RectTransform>().anchorMax;
                if (prefab != null)                                           //资源加载成功
                {
                    GameObject goWillShowUI = GameObject.Instantiate(prefab); //克隆游戏对象到层次面板上
                    //goWillShowUI.SetActive(true);
                    ui = goWillShowUI.GetComponent <UIBasePanel>();           //获取此对象上的UI
                    if (ui != null)
                    {
                        //Transform root = getUIRoot(ui);//获取UI所对应的根节点
                        //放入根节点下面
                        UtilUI.addChildToParent(transUIRoot, goWillShowUI.transform);//放入根节点下面
                        //数据的恢复
                        goWillShowUI.GetComponent <RectTransform>().offsetMin = offMin;
                        goWillShowUI.GetComponent <RectTransform>().offsetMax = offMax;
                        goWillShowUI.GetComponent <RectTransform>().anchorMin = anchorMin;
                        goWillShowUI.GetComponent <RectTransform>().anchorMax = anchorMax;
                        prefab = null;//清空预制体对象
                    }
                }
                else
                {
                    Debug.LogError("资源" + path + "不存在");
                }
            }
        }
        //2:更新显示其它的UI
        UpdateOtherUIState(ui);

        //3:显示当前UI
        dicAllUI[id]  = ui;
        dicShowUI[id] = ui;
        ui.show();
    }
Esempio n. 14
0
 public void DestroyUI(EUiId uiId, DelAfterHideUI del)
 {
     //如果该窗体没有显示出来,就不用隐藏了
     if (dicAllUI.ContainsKey(uiId))
     {
         dicAllUI[uiId].Destroy();
         dicAllUI.Remove(uiId);
         if (dicShownUI.ContainsKey(uiId))
         {
             dicShownUI.Remove(uiId);
         }
     }
 }
Esempio n. 15
0
 //隐藏该窗体
 public void HideUI(EUiId uiId, DelAfterHideUI del = null)
 {
     if (del != null)
     {
         del();
     }
     //如果该窗体没有显示出来,就不用隐藏了
     if (dicShownUI.ContainsKey(uiId))
     {
         dicShownUI[uiId].HideUI();
         dicShownUI.Remove(uiId);
     }
 }
Esempio n. 16
0
 //隐藏所有窗体
 public void HideAllUI()
 {
     if (dicShowUI.Count > 0)
     {
         foreach (var item in dicShowUI)
         {
             //隐藏正在显示的窗体
             item.Value.HideUI(null);
             //缓存上一个窗体的ID
             beforeHideUiId = item.Key;
         }
         dicShowUI.Clear();
     }
 }
Esempio n. 17
0
    //获取指定已显示的窗体
    public BaseView GetViewByUiID(EUiId eUiId)
    {
        BaseView tempView = null;

        foreach (var item in _dicShownUI)
        {
            if (item.Key == eUiId)
            {
                tempView = _dicShownUI[eUiId];
                break;
            }
        }
        return(tempView);
    }
Esempio n. 18
0
        /// <summary>
        /// 删除自身UI
        /// </summary>
        public void DestoryUI()
        {
            BaseUI currentUI = GetBaseUI(CurrentId);

            Destroy(currentUI.gameObject);
            RemoveUiId(CurrentId);

            BaseUI parentUI = currentUI.transform.GetComponentUpwards <BaseUI>();

            if (parentUI != null)
            {
                currentUI = parentUI;
                CurrentId = parentUI.UiId;
            }
        }
Esempio n. 19
0
 //隐藏单个窗体
 public void HideSingleUI(EUiId uiId, DelAfterHideUI del)
 {
     if (!dicShowUI.ContainsKey(uiId))
     {
         return;
     }
     if (del != null)
     {
         dicShowUI[uiId].HideUI(del);
     }
     else
     {
         dicShowUI[uiId].HideUI(null);
     }
     dicShowUI.Remove(uiId);
 }
Esempio n. 20
0
 public void hideUI(EUiId id, Action a = null) //隐藏UI,传入ID和需要做的事情
 {
     if (!dicShowUI.ContainsKey(id))           //正在显示的容器中没有此ID
     {
         return;
     }
     if (a == null)            //隐藏UI的时候不需要做别的事情
     {
         dicShowUI[id].hide(); //直接隐藏
         dicShowUI.Remove(id); //从显示列表中删除
     }
     else//隐藏窗体之后需要做的事情
     {
         a += delegate { dicShowUI.Remove(id); };
         dicShowUI[id].hide(a);
     }
 }
Esempio n. 21
0
 //隐藏该窗体
 public void HideTheUI(EUiId uiId, DelAfterHideUI del = null)
 {
     del?.Invoke();
     if (_dicShownUI.ContainsKey(uiId))
     {
         if (_dicShownUI[uiId].isSingleUse)
         {
             Destroy(_dicShownUI[uiId].gameObject);
             _dicAllUI.Remove(uiId);
             _dicShownUI.Remove(uiId);
         }
         else
         {
             _dicShownUI[uiId].gameObject.SetActive(false);
             _dicShownUI.Remove(uiId);
         }
     }
 }
Esempio n. 22
0
        public BaseUI JudgeShowUI(EUiId uiId, Transform parent)
        {
            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);
                        baseUI = willShowUI.GetComponent <BaseUI>();
                        if (baseUI == null)
                        {
                            Type type = GetTypeByUiId(uiId);
                            baseUI = willShowUI.AddComponent(type) as BaseUI;
                        }
                        //把生成出来的窗体放在UiRoot下面
                        willShowUI.SetParent(parent == null ? uiRoot : parent);
                        willShowUI.GetComponent <RectTransform>().sizeDelta          = Vector2.zero;
                        willShowUI.GetComponent <RectTransform>().anchoredPosition3D = Vector3.zero;
                        dicAllUI.Add(uiId, baseUI);
                    }
                    else
                    {
                        Debug.LogError("在路径" + path + "下面找不到预制体" + uiId + ",请检查路径下面是否有该预制体");
                    }
                }
                else
                {
                    Debug.LogError("GameDefine下面没有窗体ID为" + uiId + "的加载路径");
                }
            }
            UpdateDicShowUI(baseUI, !parent);
            return(baseUI);
        }
Esempio n. 23
0
    //点击返回按钮
    public void ClickReturn()
    {
        if (stackReturnInfor.Count == 0)//说明没有反向切换的信息
        {
            if (currentUI == null)
            {
                return;
            }
            EUiId beforeUiId = currentUI.beforeUiId;
            if (beforeUiId != EUiId.NullUI)
            {
                HideUI(currentUI.uiId, delegate { ShowUI(beforeUiId); });
            }
        }
        else //说明有反向切换信息
        {
            UIReturnInfor uiReturnInfor = stackReturnInfor.Peek();
            if (uiReturnInfor != null)
            {
                //获得当前窗体的ui
                EUiId theId = uiReturnInfor.willBeShowUI.uiId;
                if (dicShownUI.ContainsKey(theId))
                {
                    HideUI(theId, delegate
                    {
                        //如果是第一个窗体(depth值最大的窗体),并且没有显示出来
                        if (!dicShownUI.ContainsKey(uiReturnInfor.listReturn[0]))
                        {
                            BaseView baseUI = GetBaseUI(uiReturnInfor.listReturn[0]);
                            baseUI.ShowUI();
                            dicShownUI[baseUI.uiId] = baseUI;

                            //this.beforeUI = currentUI;
                            currentUI = baseUI;
                            //pop是把栈顶元素删除
                            stackReturnInfor.Pop();
                        }
                    });
                }
            }
        }
    }
Esempio n. 24
0
    public BaseView ShowUI(EUiId uiId)
    {
        //先判断窗体是不是正在显示(已经显出)
        if (_dicShownUI.ContainsKey(uiId))
        {
            return(null);
        }
        BaseView baseUI = JudgeShowUI(uiId);

        if (baseUI != null)
        {
            _dicShownUI[uiId] = baseUI;
            _dicShownUI[uiId].gameObject.SetActive(true);
            if (uiId == EUiId.MainView)
            {
                //重置反向切换的信息(当显示的是Mainui的时候就需要重置)
                _stackReturnInfor.Clear();
            }
        }
        return(_currentUI = baseUI);
    }
Esempio n. 25
0
    public BaseView JudgeShowUI(EUiId uiID)
    {
        //先判断窗体是不是正在显示(已经显出)
        if (dicShownUI.ContainsKey(uiID))//已经显示出来了
        {
            GetViewByUiID(uiID).Render();
            return(null);
        }
        BaseView baseUI = GetBaseUI(uiID);

        //如果baseui在字典里面没有查找到,说明该窗体还没有加载过
        if (baseUI == null)
        {
            //开始加载
            if (GameDefine.dicUIPath.ContainsKey(uiID))
            {
                GameObject theUI = null;

                string path = GameDefine.dicUIPath[uiID];
                theUI = ResourceManager.GetInstance.LoadPrefab(path, null);

                if (theUI != null)
                {
                    theUI.SetActive(true);
                    //把窗体放到对应的节点下面
                    baseUI = theUI.GetComponent <BaseView>();
                    Transform theRoot = GetUIRoot(baseUI);
                    GameTool.AddChildToParent(theRoot, theUI.transform);
                    theUI          = null;
                    dicAllUI[uiID] = baseUI;
                }
                else
                {
                    Debug.LogError("Load UI Null");
                }
            }
        }
        UpDateStack(baseUI);
        return(baseUI);
    }
Esempio n. 26
0
        public void ShowUI(EUiId nextUiId, SceneTransType transType = SceneTransType.Null, Transform parent = null, string EventTypeName = null, params object[] param)
        {
            Resources.UnloadUnusedAssets();
            GC.Collect();
            if (isInit)
            {
                AudioManager.Instance.PlayAudio();
            }
            if (!isInit)
            {
                isInit = true;
            }

            BaseUI currentUI = GetBaseUI(CurrentId);

            SceneTransition.ShowTranstion(transType,
                                          () =>
            {
                if (transType == SceneTransType.Newspaper)
                {
                }
            },
                                          () =>
            {
                if (currentUI != null && parent == null)
                {
                    //父级baseUI
                    EUiId parentUiId = EUiId.NullUI;
                    BaseUI parentUI  = currentUI.transform.GetComponentUpwards <BaseUI>();
                    if (parentUI != null)
                    {
                        parentUiId = parentUI.UiId;
                    }

                    BaseUI[] childUI = currentUI.GetComponentsInFirstHierarchyChildren <BaseUI>(true);

                    //如果父级有baseUI并且直接打开的是别的UI的话就删除
                    if (parentUiId != EUiId.NullUI && nextUiId != parentUiId)
                    {
                        Destroy(parentUI.gameObject);
                    }
                    else
                    {
                        Destroy(currentUI.gameObject);
                    }

                    RemoveUiId(CurrentId);
                    if (childUI != null)
                    {
                        for (int i = 0; i < childUI.Length; i++)
                        {
                            EUiId chiidUiId = childUI[i].UiId;
                            RemoveUiId(chiidUiId);
                        }
                    }
                    if (parentUiId != EUiId.NullUI && nextUiId != parentUiId)
                    {
                        RemoveUiId(parentUiId);
                    }
                }

                BaseUI baseUI = JudgeShowUI(nextUiId, parent);
                if (baseUI != null)
                {
                    baseUI.HideUI();
                    if (EventTypeName != null)
                    {
                        SwanEngine.Events.Dispatcher.Instance.DispathEvent(EventTypeName, param);
                    }
                    //CurrentId = nextUiId;
                    baseUI.ShowUI();

                    /* 到时候可能要改成这样,因为在OnEnable的时候Enable还为false,不能调用协程
                     * baseUI.ShowUI();
                     * if (EventTypeName != null)
                     *  SwanEngine.Events.Dispatcher.Instance.DispathEvent(EventTypeName, param);
                     */
                }
                CurrentId = nextUiId;
            });
            Resources.UnloadUnusedAssets();
            GC.Collect();
        }
Esempio n. 27
0
 public void hideUILater(EUiId id, float later, Action a = null)//隐藏UI,传入ID和需要做的事情
 {
     StartCoroutine(hideUIMain(id, later, a));
 }
Esempio n. 28
0
    IEnumerator hideUIMain(EUiId id, float time, Action a = null)
    {
        yield return(new WaitForSeconds(time));

        hideUI(id, a);
    }
Esempio n. 29
0
    IEnumerator showUILater(EUiId id, float time)
    {
        yield return(new WaitForSeconds(time));

        showUI(id);
    }
Esempio n. 30
0
 public void showLater(EUiId id, float time)
 {
     StartCoroutine(showUILater(id, time));
 }