示例#1
0
        public void GetInstance(string key, bool shared, Action <PopupBase> callback)
        {
            var data = new PopupLoadData(key, shared, callback);

            InputBlocker.Show(this);
            loadList.Enqueue(data);
        }
示例#2
0
        private IEnumerator LoadInstance(PopupLoadData loadData)
        {
            log.Debug("Instantiate '{0}'", loadData.key);
            ResourceRequest req = Resources.LoadAsync(loadData.key);

            yield return(req);

            GameObject prefab = req.asset as GameObject;

            if (prefab != null)
            {
                GameObject inst = Object.Instantiate(prefab);
                inst.SetActive(true);
                PopupBase p = inst.GetComponent <PopupBase>();
                p.shared = loadData.shared;
                p.transform.SetParent(transform, false);
                if (loadData.shared)
                {
                    instanceMap[loadData.key] = p;
                    lruCache.Remove(loadData.key);
                    lruCache.Add(loadData.key);
                    // check cache size
                    if (!IsImmortal(p.GetType()))
                    {
                        if (lruCache.Count > CACHE_SIZE)
                        {
                            string    head     = lruCache[0];
                            PopupBase oldPopup = instanceMap[head];
                            if (oldPopup.window.Status == UIPanelStatus.Hidden)
                            {
                                log.Debug("Destroy '{0}'", oldPopup.name);
                                instanceMap.Remove(head);
                                oldPopup.gameObject.DestroyEx();
                                lruCache.RemoveAt(0);
                            }
                        }
                    }
                }
                loadData.Complete(p);
            }
            else
            {
                log.Error("Popup '{0}' is missing", loadData.key);
                loadData.Complete(null);
            }
        }
示例#3
0
        void Update()
        {
            if (currLoading != null)
            {
                if (currLoading.consumed)
                {
                    currLoading = null;
                }
                else if (currLoading.shared)
                {
                    PopupBase p = instanceMap.Get(currLoading.key);
                    if (p != null && p.window.Status.IsShowing())
                    {
                        currLoading = null;
                    }
                }
            }
            if (loadList.Count > 0 && currLoading == null)
            {
                currLoading = loadList.Dequeue();
                PopupBase p = null;
                if (currLoading.shared)
                {
                    lruCache.Remove(currLoading.key);
                    lruCache.Add(currLoading.key);
                    p = instanceMap.Get(currLoading.key);
                }

                if (p != null)
                {
                    currLoading.Complete(p);
                }
                else
                {
                    StartCoroutine(LoadInstance(currLoading));
                }
            }
        }