コード例 #1
0
        private void RemoveFocusStack(int viewId)
        {
            int index = _focusViewStack.IndexOf(viewId);

            if (index == -1)
            {
                return;
            }
            // 不是最上层的焦点界面
            if (index != _focusViewStack.Count - 1)
            {
                _focusViewStack.RemoveAt(index);
            }
            else
            {
                _focusViewStack.RemoveAt(index);
                // 切换焦点界面
                if (_focusViewStack.Count > 0)
                {
                    int nextFocusId = _focusViewStack[_focusViewStack.Count - 1];
                    _curFocusView = GetView(nextFocusId).GetViewObject().GetComponent <UView>();
                    EventManager.GetInstance().PostEvent(EngineEventID.WindowFocusChanged, nextFocusId);
                }
                else
                {
                    _curFocusView = null;
                    Logger.Log("NoFocus View");
                }
            }
        }
コード例 #2
0
        private void FocusOnView(int viewId)
        {
            int index = _focusViewStack.IndexOf(viewId);

            if (index != -1)
            {
                // 若viewId对应的界面正是当前的焦点界面
                // 则直接返回
                if (viewId == GetFocusViewId())
                {
                    return;
                }
                _focusViewStack.RemoveAt(index);
            }
            _focusViewStack.Add(viewId);
            ViewBase view = GetView(viewId);

            if (view != null)
            {
                _curFocusView = view.GetViewObject().GetComponent <UView>();
            }
            else
            {
                throw new Exception(string.Format("Add focus stack error!view of id {0} is not exitst.", viewId));
            }
            EventManager.GetInstance().PostEvent(EngineEventID.WindowFocusChanged, viewId);
        }
コード例 #3
0
        private void UIRootClickHandler()
        {
            PointerEventData eventData = new PointerEventData(_eventSystem);

            eventData.position = Input.mousePosition;
            List <RaycastResult> resultList = new List <RaycastResult>();

            _rayCaster.Raycast(eventData, resultList);
            // 检测到第一个界面
            foreach (RaycastResult result in resultList)
            {
                GameObject curGo = result.gameObject;
                Transform  curTf = curGo.transform;
                while (curTf.GetComponent <UView>() == null)
                {
                    curTf = curTf.parent;
                }
                UView focusView = curTf.GetComponent <UView>();
                if (focusView.focusWhenOpen)
                {
                    FocusOnView(focusView.GetView().ViewId);
                    break;
                }
            }
        }
コード例 #4
0
 private void InitFocus()
 {
     _eventSystem    = GameObject.Find("EventSystem").GetComponent <EventSystem>();
     _rayCaster      = _uiRoot.GetComponent <GraphicRaycaster>();
     _curFocusView   = null;
     _focusViewStack = new List <int>();
 }
コード例 #5
0
        public void OpenView(int viewId, object data, Vector2 pos)
        {
            ViewCfg cfg = null;

            if (!_viewCfgs.TryGetValue(viewId, out cfg))
            {
                return;
            }
            ViewBase view;

            if (!_viewsMap.TryGetValue(viewId, out view))
            {
                GameObject viewGo = ResourceManager.GetInstance().GetPrefab("Prefabs/Views", cfg.resPath);
                if (viewGo != null)
                {
                    // 创建viewBase
                    System.Type classType = System.Type.GetType(cfg.className);
                    view = System.Activator.CreateInstance(classType) as ViewBase;
                    // uviw初始化,切换窗口焦点
                    // 切换焦点
                    UView uview = viewGo.GetComponent <UView>();
                    uview.Init(view);
                    // view初始化
                    view.Init(viewId, viewGo);
                    _viewsMap.Add(viewId, view);
                    Transform parentTf;
                    if (!_layersMap.TryGetValue(cfg.layer, out parentTf))
                    {
                        parentTf = _layersMap[LayerId.Normal];
                    }
                    RectTransform viewTf = viewGo.GetComponent <RectTransform>();
                    viewTf.SetParent(parentTf, false);
                    SetUIPosition(viewTf, pos);
                    // 设置焦点界面
                    if (uview.focusWhenOpen)
                    {
                        FocusOnView(viewId);
                    }
                    // OnShow接口
                    view.OnShowImpl(data);
                }
            }
            else
            {
                GameObject viewGo = view.GetViewObject();
                // 切换焦点
                UView uview = viewGo.GetComponent <UView>();
                if (uview.focusWhenOpen)
                {
                    FocusOnView(viewId);
                }
                view.Refresh(data);
                viewGo.transform.SetSiblingIndex(-1);
            }
        }