Beispiel #1
0
            public void LoadPageResAsync(int uiID, Transform parent, bool singleton, Action <AbstractPage> listener)
            {
                UIData data = UIDataTable.Get(uiID);

                if (data == null)
                {
                    Log.e("Failed to load UI, Not Find UIData For:" + uiID);
                    return;
                }

                if (singleton)
                {
                    if (m_PageWrapList == null)
                    {
                        m_PageWrapList = new List <PageWrap>();
                    }

                    PageWrap wrap = FindPageWrap(uiID);

                    if (wrap != null)
                    {
                        wrap.AddListener(listener);
                        return;
                    }
                    else
                    {
                        wrap = new PageWrap(uiID);
                        wrap.AddListener(listener);

                        m_PageWrapList.Add(wrap);
                    }
                }

                PrepareDynamicResource(data);

                m_ResLoader.Add2Load(data.fullPath, (state, res) =>
                {
                    if (!state)
                    {
                        return;
                    }

                    OnPageResLoadSuccess(uiID, parent, (GameObject)res.asset, singleton, listener);
                });

                m_ResLoader.LoadSync();
            }
Beispiel #2
0
        private PanelInfo LoadPanelInfo(int uiID)
        {
            UIData data = UIDataTable.Get(uiID);

            if (data == null)
            {
                Log.e("Failed to OpenPanel, Not Find UIData for UIID:" + uiID);
                return(null);
            }

            bool      needAdd   = true;
            PanelInfo panelInfo = GetPanelFromCache(uiID, true);

            if (panelInfo == null)
            {
                //缓存中没有,判断当前Panel 是否只支持单例
                if (data.isSingleton)
                {
                    //去当前所有已经开启的面板中寻找
                    panelInfo = GetPanelFromActive(uiID);
                }

                if (panelInfo == null)
                {
                    panelInfo = ObjectPool <PanelInfo> .Instance.Allocate();

                    panelInfo.Set(uiID, nextPanelID);
                }
                else
                {
                    needAdd = false;
                }
            }

            if (needAdd)
            {
                AddPanelInfo(panelInfo);
            }

            return(panelInfo);
        }
Beispiel #3
0
        public void UnShortCachePanel <T>(T uiID, bool clean = true) where T : IConvertible
        {
            UIData data = UIDataTable.Get(uiID.ToInt32(null));

            if (data == null)
            {
                return;
            }

            data.shortCacheCount = 0;

            if (data.cacheCount > 0)
            {
                return;
            }

            if (!clean)
            {
                return;
            }

            for (int i = m_CachedPanelList.Count - 1; i >= 0; --i)
            {
                if (i >= m_CachedPanelList.Count)
                {
                    continue;
                }

                PanelInfo panelInfo = m_CachedPanelList[i];

                UIData data2 = UIDataTable.Get(panelInfo.uiID);
                if (data2.cacheCount < 1)
                {
                    m_CachedPanelList.RemoveAt(i);

                    GameObject.Destroy(panelInfo.abstractPanel.gameObject);

                    ObjectPool <PanelInfo> .Instance.Recycle(panelInfo);
                }
            }
        }
Beispiel #4
0
            //收集预加载资源
            private void PrepareDynamicResource(UIData data)
            {
                if (data == null || data.panelClassType == null)
                {
                    return;
                }

                //TimeDebugger timer = new TimeDebugger("PrepareDynamicResource");
                //timer.Begin("P1");
                var methodInfo = data.panelClassType.GetMethod("PrepareDynamicResource", System.Reflection.BindingFlags.Static |
                                                               System.Reflection.BindingFlags.Public);

                //timer.End();

                if (methodInfo == null)
                {
                    //timer.Dump(-1);
                    return;
                }

                //timer.Begin("P2");
                object result = methodInfo.Invoke(null, null);

                if (result == null)
                {
                    return;
                }

                if (result is List <string> )
                {
                    m_ResLoader.Add2Load((List <string>)result);
                }
                else if (result is string)
                {
                    m_ResLoader.Add2Load((string)result);
                }
                //timer.End();
                //timer.Dump(-1);
            }
Beispiel #5
0
        public static void Add(UIData data)
        {
            if (data == null)
            {
                return;
            }

            if (m_UIDataMap.ContainsKey(data.uiID))
            {
                Log.w("Already Add UIData:" + data.uiID);
                return;
            }

            m_UIDataMap.Add(data.uiID, data);

            string shortName   = data.name;
            int    folderIndex = shortName.LastIndexOf('/');

            if (folderIndex >= 0)
            {
                shortName = shortName.Substring(folderIndex + 1);
            }
            m_UINameDataMap.Add(shortName, data);
        }