示例#1
0
 /// <summary>
 /// 检查缓存区~如果超过最大上限值,则进行清理,如果链存在不进行清理,一般情况下,链的长度不会超过缓存大小
 /// </summary>
 private void CheckCach()
 {
     if (cacheWndDict.Count < MAX_CACH_WND)
     {
         return;
     }
     else
     {
         int       minDepth = MAX_CACH_WND;
         UIWndBase wnd      = null;
         foreach (KeyValuePair <WindowID, UIWndBase> pair in cacheWndDict)
         {
             if (pair.Value.Depth < minDepth && !backStack.Contains(pair.Value))
             {
                 minDepth = pair.Value.Depth;
                 wnd      = pair.Value;
             }
         }
         if (wnd != null)
         {
             Log("当前窗口缓存过大 清理窗口 id = " + wnd.wndID);
             Destroy(wnd.gameObject);
             cacheWndDict.Remove(wnd.wndID);
         }
     }
 }
示例#2
0
 /// <summary>
 /// 向指定窗口发送消息
 /// </summary>
 public void SendMsg(WindowID wndId, WindowMsgID msgId, object param)
 {
     if (cacheWndDict.ContainsKey(wndId))
     {
         UIWndBase wnd = cacheWndDict [wndId];
         wnd.OnMsg(msgId, param);
     }
     else
     {
         Log("窗口不在缓存中, 事件更新失败");
     }
 }
示例#3
0
        private void RealShow(WindowID windowId, bool bAppend)
        {
            string     wndPath   = wndResDict [windowId];
            string     panelPath = string.Format("{0}Panel/{1}", AssetDefine.ResRoot, windowId.ToString());
            GameObject prefab    = ResourcesManager.Load <GameObject>(panelPath);

            if (prefab != null)
            {
                GameObject clone = (GameObject)GameObject.Instantiate(prefab);
                XFramework.Utility.Util.AddChildToTarget(wndRoot.transform, clone.transform);
                UIWndBase wnd = clone.GetComponent <UIWndBase> ();
                wnd.status = WindowStatus.Active;
                if (curShowWnd != null)
                {
                    wnd.preWndID = curShowWnd.wndID;
                }
                wnd.wndID = windowId;
                if (bAppend)
                {
                    Log("push into stack " + curShowWnd.wndID.ToString());
                    if (backStack.Count == 0)
                    {
                        backStack.Push(curShowWnd);
                    }
                    curShowWnd = wnd;
                    backStack.Push(curShowWnd);
                    AdjustAlpha();
                }
                else
                {
                    curShowWnd = wnd;
                    HideAllCach();
                    BreakBackStack();
                }
                cacheWndDict.Add(windowId, curShowWnd);
                curShowWnd.AdjustAlpha(1.0f);
                CheckCach();
                wnd.Refresh();
            }
        }
示例#4
0
        /// <summary>
        /// 窗口显示,队列型加载
        /// </summary>
        public void ShowWindow(WindowID windowId, bool bAppend = false)
        {
            if (instance == null)
            {
                Init();
            }
            if (FrameRoot == null)
            {
                GameObject prefab = ResourcesManager.Load <GameObject>("BuildIn/Frame/UIFrame");
                FrameRoot = Util.NewGameObject(prefab, wndRoot).GetComponent <UIFrame>();
            }
            FrameRoot.Init(windowId);

            if (wndResDict.ContainsKey(windowId))
            {
                if (cacheWndDict.ContainsKey(windowId))
                {
                    UIWndBase wnd = cacheWndDict [windowId];
                    Log("缓存中, 状态是:" + wnd.status.ToString());
                    if (wnd.status == WindowStatus.Inactive)
                    {
                        if (bAppend)
                        {
                            if (backStack.Count == 0)
                            {
                                backStack.Push(curShowWnd);
                            }
                            backStack.Push(wnd);
                            AdjustAlpha();
                        }
                        else
                        {
                            HideAllCach();
                            BreakBackStack();
                            curShowWnd.Close();
                        }
                        wnd.Show();
                        curShowWnd = wnd;
                    }
                    else if (wnd.status == WindowStatus.Gray)
                    {
                        curShowWnd.Close();
                        curShowWnd = wnd;
                        backStack.Pop();
                        AdjustAlpha();
                    }
                    else if (wnd.status == WindowStatus.Active)
                    {
                        Log("当前窗口已经是显示窗口");
                    }
                    wnd.Refresh();
                }
                else
                {
                    Log("新加入窗口:" + windowId.ToString());
                    RealShow(windowId, bAppend);
                }
            }
            else
            {
                Log(windowId.ToString() + " 不存在资源");
            }
        }