Ejemplo n.º 1
0
        private IUIEntity POpenUI(string ui_path, bool use_mask, bool close_by_mask, int ParentID = -1, string uiName = "unknow", System.Object OpenParam = null)
        {
            //先找找这个UI在不在
            foreach (var item in mUIPool)
            {
                if (item.Value.UIPath == ui_path)
                {
                    //存在了
                    if (!item.Value.IsMultiUI)
                    {
                        //置顶UI并返回

                        return(item.Value.GetUIEntityAPI());
                    }
                    break;
                }
            }

            //走到这儿就说明肯定得新建UI了
            var ui_prefab = mVFS.LoadAsset <GameObject>(ui_path);
            //创建UI对象
            var ui_item = new UIItem(ui_prefab, ui_path, mGateway);

            //初始化UI
            ui_item.InitUI();   //UI对象内部自己处理层级
            //分配ID
            var ui_id = GetFreeUIPoolID();

            ui_item.SetID(ui_id);
            //如有父UI,记录
            if (ParentID != -1)
            {
                if (mUIPool.ContainsKey(ParentID))
                {
                    mUIPool[ParentID].AddChild(ui_item.GetUIEntity());
                }
            }

            //遮罩处理
            if (use_mask)
            {
                ui_item.UseMask(close_by_mask);
            }

            //记录UI
            mUIPool.Add(ui_id, ui_item);

            //处理Entity的事件
            ui_item.GetUIEntity().OnUICreated(ui_path, uiName);
            //处理打开UI参数传递
            if (OpenParam != null)
            {
                ui_item.GetUIEntity().OnUIOpenMessage(OpenParam);
            }


            //返回
            return(ui_item.GetUIEntityAPI());
        }
Ejemplo n.º 2
0
        public void OnUIClose(UIItem ui_item)
        {
            if (ui_item.LayerIndex == mCurMaxLayer)
            {
                //将被关掉的是最顶级的UI;
                mCurMaxLayer -= 10;
            }
            var entity = ui_item.GetUIEntity();

            if (entity.IsFullScreenUI)
            {
                mFullScreen_GameObject_List.Remove(entity);
                //全屏
                if (mCur_Active_FullScreenUI == entity)
                {
                    //将被关掉的就是最顶级UI,找到上一个UI并放出来
                    if (mFullScreen_GameObject_List.Count > 0)
                    {
                        mCur_Active_FullScreenUI = mFullScreen_GameObject_List[mFullScreen_GameObject_List.Count - 1];
                        //放出来
                        mCur_Active_FullScreenUI.gameObject.Show();
                        var rect_trans = mCur_Active_FullScreenUI.gameObject.GetComponent <RectTransform>();
                        rect_trans.anchoredPosition3D = Vector3.zero;
                    }
                    else
                    {
                        mCur_Active_FullScreenUI = null;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 打开UI
        /// </summary>
        /// <param name="ui_path">UI路径</param>
        private IUIEntity POpenUI(string ui_path, bool use_mask, bool close_by_mask, string uiName = "unknow", System.Object OpenParam = null, XLua.LuaTable LuaParam = null)
        {
            //检查UI对象是否已存在
            if (mUIPool.ContainsKey(ui_path))
            {
                //存在,直接置顶
                mGateway.SetUILayerTop(mUIPool[ui_path].GetUIEntity());
                return(mUIPool[ui_path].GetUIEntityAPI());
            }
            else
            {
                //不存在,打开流程
                var ui_prefab = mVFS.LoadAsset <GameObject>(ui_path);
                //创建UI对象
                var ui_item = new UIItem(ui_prefab, ui_path, mGateway);
                //初始化UI
                ui_item.InitUI();   //UI对象内部自己处理层级
                //遮罩处理
                if (use_mask)
                {
                    ui_item.UseMask(close_by_mask);
                }
                //记录UI
                mUIPool.Add(ui_path, ui_item);

                //处理Entity的事件
                ui_item.GetUIEntity().OnUICreated(ui_path, uiName);
                //处理打开UI参数传递
                if (OpenParam != null)
                {
                    ui_item.GetUIEntity().OnUIOpenMessage(OpenParam);
                }

                if (LuaParam != null)
                {
                    ui_item.GetUIEntity().OnUIOpenMessage_LuaTable(LuaParam);
                }


                //返回
                return(ui_item.GetUIEntityAPI());
            }
        }
Ejemplo n.º 4
0
        public void OnUIClose(UIItem ui_item)
        {
            //if(ui_item.LayerIndex == mCurMaxLayer)
            //{
            //    //将被关掉的是最顶级的UI;
            //    mCurMaxLayer -= 10;
            //}
            var entity = ui_item.GetUIEntity();

            for (var i = mUIPool.Count - 1; i >= 0; i--)
            {
                if (mUIPool[i] != entity)
                {
                    //被关掉的不是最顶层的UI
                    //把这个UI上面的UI层级依次减10
                    mUIPool[i].SetLayer(mUIPool[i].LayerIndex - 10);
                }
                else
                {
                    mUIPool.RemoveAt(i);
                    break;
                }
            }

            //var entity = ui_item.GetUIEntity();
            if (entity.IsFullScreenUI)
            {
                mFullScreen_GameObject_List.Remove(entity);
                //全屏
                if (mCur_Active_FullScreenUI == entity)
                {
                    //将被关掉的就是最顶级UI,找到上一个UI并放出来
                    if (mFullScreen_GameObject_List.Count > 0)
                    {
                        mCur_Active_FullScreenUI = mFullScreen_GameObject_List[mFullScreen_GameObject_List.Count - 1];
                        //放出来
                        mCur_Active_FullScreenUI.gameObject.Show();
                        var rect_trans = mCur_Active_FullScreenUI.gameObject.GetComponent <RectTransform>();
                        rect_trans.anchoredPosition3D = Vector3.zero;
                    }
                    else
                    {
                        mCur_Active_FullScreenUI = null;
                    }
                }
            }
        }