コード例 #1
0
ファイル: UIManager.cs プロジェクト: Joker4321/666
        //供外界调用的,显示窗体的方法
        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);
        }
コード例 #2
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();
        }