Example #1
0
    private static T Create <T>(List <UiCacheInstance> caches, List <UiCacheInstance> actives, Transform parent = null) where T : UiCacheInstance
    {
        UiCacheInstance inst = null;

        if (caches.Count == 0)
        {
            if (actives.Count > 0)
            {
                Recycle(actives[0], actives[0].GetType());
            }
        }

        if (caches.Count > 0)
        {
            inst         = caches[0];
            inst.InCache = false;
            inst.SetActiveByCanvasGroup(true);
            caches.RemoveAt(0);
        }


        if (inst == null)
        {
            Debug.LogError("GetInstFromPool == null, 池内没有可用的UIInst,Type:" + typeof(T));
        }
        else
        {
            actives.Add(inst);

            //parent
            if (parent == null)
            {
                var t = UiManager.GetCanvas(inst.UiInfo.Layer);
                inst.TransForm.SetParent(t, false);
                inst.TransForm.SetAsLastSibling();
            }
            else
            {
                inst.transform.SetParent(parent, false);
                inst.TransForm.SetAsLastSibling();
            }
        }

        return(inst as T);
    }
Example #2
0
    protected static void Recycle(UiCacheInstance inst, Type t)
    {
        if (inst.InCache)
        {
            return;
        }

        var actives = GetActiveInstances(t);

        actives.Remove(inst);

        var caches = GetCachePool(t);

        //缓存满了,直接destroy
        if (caches.Count >= inst.GetMaxCacheCount())
        {
            inst.Close();
        }
        else
        {
            inst.InCache = true;
            inst.SetActiveByCanvasGroup(false);
            inst.OnRecycle();

            if (inst.TransForm.parent != CacheRoot)
            {
                inst.InCache = true;
                inst.TransForm.SetParent(CacheRoot, false);
            }

            if (!caches.Contains(inst))
            {
                caches.Add(inst);
            }
        }
    }
Example #3
0
 public static void Clear()
 {
     UiFullView.Clear();
     UiCacheInstance.BackAllToPool();
     ClearAllUi();
 }