Пример #1
0
    public void ReleaseObj(GameObject obj, int maxCacheCount = -1, bool isDestroyCache = false, bool isRecyleParent = false)
    {
        var    insID  = obj.GetInstanceID();
        ResObj resObj = null;

        if (resObjDic.TryGetValue(insID, out resObj))
        {
            Debug.LogWarningFormat("{0} obj is not created by ObjMgr", obj.name);
            return;
        }
        if (resObj.IsCachePool)
        {
            Debug.LogWarningFormat("{0} obj recyled to cache pool", obj.name);
            return;
        }

#if UNITY_EDITOR
        obj.name += "(Recycle)";
#endif

        if (maxCacheCount == 0)
        {
            resObjDic.Remove(insID);
            ResSvc.Ins.ReleaseRes(resObj.CRC, false);
            resObj.Reset();
            resObjPool.Recycle(resObj);
        }
        else
        {
            List <ResObj> list = null;
            if (!objCachePoolDic.TryGetValue(resObj.CRC, out list))
            {
                list = new List <ResObj>();
                objCachePoolDic.Add(resObj.CRC, list);
            }
            if (recyleRoot)
            {
                resObj.CloneObj.transform.SetParent(recyleRoot);
            }
            else
            {
                resObj.CloneObj.SetActive(false);
            }

            if (maxCacheCount < 0 || list.Count < maxCacheCount)
            {
                list.Add(resObj);
                resObj.IsCachePool = true;
                //ResSvc.Ins.DecreaseResRef(resObj.CRC);
            }
            else
            {
                resObjDic.Remove(insID);
                ResSvc.Ins.ReleaseRes(resObj.CRC, false);
                resObj.Reset();
                resObjPool.Recycle(resObj);
            }
        }
    }
Пример #2
0
    public void CancelCreatIns(long guid)
    {
        ResObj resObj = null;

        if (createingResObjs.TryGetValue(guid, out resObj) && ResSvc.Ins.CancelLoadAsset(resObj))
        {
            createingResObjs.Remove(guid);
            resObj.Reset();
            resObjPool.Recycle(resObj);
        }
    }