Example #1
0
        public void ClosePopPanelByID(int panelID)
        {
            UI_Commond newCommond = new UI_Commond()
            {
                operation_type      = UI_Commond_Type.Close,
                operation_id        = panelID,
                operation_panelType = -1
            };

            commonds_queue.Enqueue(newCommond);
            if (taskCoroutine is null)
            {
                taskCoroutine = StartCoroutine(ExcuteTask());
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="panelType">class UI_Panel</param>
        public void ShowPopPanelByType(int panelType)
        {
            UI_Commond newCommond = new UI_Commond()
            {
                operation_type      = UI_Commond_Type.Show,
                operation_panelType = panelType,
                operation_id        = -1
            };

            commonds_queue.Enqueue(newCommond);
            if (taskCoroutine is null)
            {
                taskCoroutine = StartCoroutine(ExcuteTask());
            }
        }
Example #3
0
        IEnumerator ExcuteTask()
        {
            if (commonds_queue.Count == 0)
            {
                yield break;
            }
            while (commonds_queue.Count > 0)
            {
                UI_Commond commond = commonds_queue.Dequeue();
                if (commond.operation_type == UI_Commond_Type.Show)
                {
                    if (commond.operation_id != -1)
                    {
                        Debug.LogError("不能根据id显示界面!");
                    }
                    int  panelType             = commond.operation_panelType;
                    bool hasShow               = false;
                    List <UI_PanelBase> loaded = null;
                    if (UI_Type_Loaded_Dic.ContainsKey(panelType))
                    {
                        loaded = UI_Type_Loaded_Dic[panelType];
                        if (loaded != null && loaded.Count > 0)
                        {
                            int loadedCount = loaded.Count;
                            for (int i = 0; i < loadedCount; i++)
                            {
                                if (loaded[i].State == UI_State.Close)
                                {
                                    loaded[i].transform.SetAsLastSibling();
                                    yield return(loaded[i].ShowThisPanel());

                                    hasShow = true;
                                    while (UI_PopPanel_Stack.Count > 0)
                                    {
                                        UI_PanelBase top = UI_PopPanel_Stack.Peek();
                                        switch (top.State)
                                        {
                                        case UI_State.Show:
                                            top.PauseThisPanel();
                                            break;

                                        case UI_State.Pause:
                                            Debug.LogError("未知暂停状态的面板!");
                                            break;

                                        case UI_State.Close:
                                            UI_PopPanel_Stack.Pop();
                                            continue;

                                        case UI_State.Unknow:
                                            break;
                                        }
                                        break;
                                    }
                                    UI_PopPanel_Stack.Push(loaded[i]);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            UI_Type_Loaded_Dic.Remove(panelType);
                            loaded = new List <UI_PanelBase>();
                            UI_Type_Loaded_Dic.Add(panelType, loaded);
                        }
                    }
                    else
                    {
                        loaded = new List <UI_PanelBase>();
                        UI_Type_Loaded_Dic.Add(panelType, loaded);
                    }
                    if (!hasShow)
                    {
                        if (UI_Type_Prefab_Dic.ContainsKey(panelType))
                        {
                            if (UI_Type_Prefab_Dic[panelType] is null)
                            {
                                Debug.LogError("加载的预制体为空!");
                                continue;
                            }
                            UI_PanelBase panel = Instantiate(UI_Type_Prefab_Dic[panelType], popRoot).GetComponent <UI_PanelBase>();
                            panel.transform.SetAsLastSibling();
                            yield return(panel.ShowThisPanel());

                            UI_Type_Loaded_Dic[panelType].Add(panel);
                            UI_ID_Loaded_Dic.Add(panel.UI_ID, panel);
                            hasShow = true;
                            while (UI_PopPanel_Stack.Count > 0)
                            {
                                UI_PanelBase top = UI_PopPanel_Stack.Peek();
                                switch (top.State)
                                {
                                case UI_State.Show:
                                    top.PauseThisPanel();
                                    break;

                                case UI_State.Pause:
                                    Debug.LogError("未知暂停状态的面板!");
                                    break;

                                case UI_State.Close:
                                    UI_PopPanel_Stack.Pop();
                                    continue;

                                case UI_State.Unknow:
                                    break;
                                }
                                break;
                            }
                            UI_PopPanel_Stack.Push(panel);
                        }
                        else
                        {
                            if (UI_Type_Path_Dic.ContainsKey(panelType))
                            {
                                GameObject prefab = Resources.Load <GameObject>(UI_Prefab_Path_Pre + UI_Type_Path_Dic[panelType]);
                                if (prefab is null)
                                {
                                    Debug.LogError("预制体路径错误!");
                                    continue;
                                }
                                else
                                {
                                    UI_Type_Prefab_Dic.Add(panelType, prefab);
                                    UI_PanelBase panel = Instantiate(UI_Type_Prefab_Dic[panelType], popRoot).GetComponent <UI_PanelBase>();
                                    if (panel is UI_PopPanelBase)
                                    {
                                    }
                                    else
                                    {
                                        panel.transform.SetParent(menuRoot);
                                    }
                                    panel.transform.SetAsLastSibling();
                                    yield return(panel.ShowThisPanel());

                                    UI_Type_Loaded_Dic[panelType].Add(panel);
                                    UI_ID_Loaded_Dic.Add(panel.UI_ID, panel);
                                    hasShow = true;
                                    while (UI_PopPanel_Stack.Count > 0)
                                    {
                                        UI_PanelBase top = UI_PopPanel_Stack.Peek();
                                        switch (top.State)
                                        {
                                        case UI_State.Show:
                                            top.PauseThisPanel();
                                            break;

                                        case UI_State.Pause:
                                            Debug.LogError("未知暂停状态的面板!");
                                            break;

                                        case UI_State.Close:
                                            UI_PopPanel_Stack.Pop();
                                            continue;

                                        case UI_State.Unknow:
                                            break;
                                        }
                                        break;
                                    }
                                    UI_PopPanel_Stack.Push(panel);
                                }
                            }
                            else
                            {
                                Debug.LogError("没有配置预制体路径!");
                                continue;
                            }
                        }
                    }
                }
                else
                {
                    if (UI_ID_Loaded_Dic.ContainsKey(commond.operation_id))
                    {
                        UI_State oldState = UI_ID_Loaded_Dic[commond.operation_id].State;
                        if (oldState != UI_State.Close)
                        {
                            yield return(UI_ID_Loaded_Dic[commond.operation_id].CloseThisPanel());

                            if (oldState == UI_State.Show)
                            {
                                while (UI_PopPanel_Stack.Count > 0 && UI_PopPanel_Stack.Peek().State == UI_State.Close)
                                {
                                    UI_PopPanel_Stack.Pop();
                                }
                                if (UI_PopPanel_Stack.Count > 0 && UI_PopPanel_Stack.Peek().State == UI_State.Pause)
                                {
                                    UI_PopPanel_Stack.Peek().ResumeThisPanel();
                                }
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError("不存在该id的面板!");
                    }
                }
            }
            taskCoroutine = null;
        }