コード例 #1
0
        public override void Init()
        {
            base.Init();
            //加载uiRootprefab , 加载依赖AssetManager,需要保证AssetManager已经完成了初始化
            var uiSetting_prefab = AssetManager.Instance.LoadAsset <UISetting>(GameConfigs.GetUIPath("UIRoot"));

            _uiSetting = GameObject.Instantiate <UISetting>(uiSetting_prefab, this.transform);
            Debug.Assert(_uiSetting != null, "初始化UI管理器失败!");
        }
コード例 #2
0
        public void OpenView(ViewID viewID, OpenViewTag openTag = OpenViewTag.Nune, bool needAnim = true, UnityAction onComplate = null, params object[] args)
        {
            BaseView view = null;

            this._viewDic.TryGetValue(viewID, out view);
            if (view != null)
            {
                Debug.Log("[UIManager] OpenView: " + viewID);

                ViewConfigData viewCfgData = view.ViewData;

                switch (openTag)
                {
                case OpenViewTag.HidePrevious: {
                    if (this._navigationStack.Count > 0)
                    {
                        CloseView(this._navigationStack.Peek().viewID, false, false, null);
                    }
                }
                break;
                }

                if (viewCfgData._isNavigation)
                {
                    pushToNavigation(new ViewNavigationData()
                    {
                        viewID = viewCfgData._viewID, data = args
                    });
                }

                switch (viewCfgData._mountLayer)
                {
                case ViewMountLayer.Fixed: {
                    refreshSibling(view, this.FixedLayer);
                }
                break;

                case ViewMountLayer.Popup: {
                    refreshSibling(view, this.PopupLayer);
                }
                break;

                case ViewMountLayer.MessageBox: {
                    refreshSibling(view, this.MessageBoxLayer);
                }
                break;
                }


                view.gameObject.SetActive(true);
                view.OnShowView(needAnim, onComplate, args);
            }
            else
            {
                Debug.Log("[UIManager] loadView: " + viewID);
                AssetManager.Instance.LoadAssetAsync <BaseView>(GameConfigs.GetUIPath(UIDefine.viewPaths[viewID]), (BaseView viewPrefab) => {
                    view = GameObject.Instantiate(viewPrefab).GetComponent <BaseView>();

                    switch (view.ViewData._mountLayer)
                    {
                    case ViewMountLayer.Fixed: {
                        view.transform.SetParent(this.FixedLayer);
                    }
                    break;

                    case ViewMountLayer.Popup: {
                        view.transform.SetParent(this.PopupLayer);
                    }
                    break;

                    case ViewMountLayer.MessageBox: {
                        view.transform.SetParent(this.MessageBoxLayer);
                    }
                    break;
                    }

                    RectTransform rt = view.GetComponent <RectTransform>();
                    rt.anchorMin     = Vector2.zero;
                    rt.anchorMax     = Vector2.one;
                    rt.offsetMin     = Vector2.zero;
                    rt.offsetMax     = Vector2.one;

                    view.transform.localScale    = Vector3.one;
                    view.transform.localPosition = Vector3.zero;
                    view.gameObject.name         = viewID.ToString();
                    GameUtils.SetLayer(view.gameObject, LayerMask.NameToLayer("UI"));
                    view.Init();

                    this._viewDic.Add(viewID, view);

                    OpenView(viewID, openTag, needAnim, onComplate, args);
                });
            }
        }