示例#1
0
        /*private void Update()
         * {
         *  mPoolRoot.name = string.Format("PoolRoot_{0}/{1}", mDicObjPools [ObjCachePoolType.SMALL_PREFAB].get_free_cache_count() , mDicObjPools [ObjCachePoolType.SMALL_PREFAB].get_cache_count());
         * }*/

        //load c# object from pool, it not found in pool, return null
        //notice: if you got object by this method, you should call RecycleCSharpObject() after using it.
        public T TryLoadCSharpObject <T>(ObjCachePoolType poolType, string poolKey) where T : class
        {
            if (poolKey == null)
            {
                return(null);
            }

            ObjectCachePool dstPool = null;

            if (!mDicObjPools.TryGetValue(poolType, out dstPool))
            {
                Debug.LogError(string.Format("ObjCachePoolMgr::TryLoadCSharpObject pool type {0} is not defined!", poolType));
                return(null);
            }

            //try load from pool
            return(dstPool.try_hit_cache(poolKey) as T);
        }
示例#2
0
        //load a prefab from pool, it not found in pool, return null
        //notice: if you got object by this method, you should call RecyclePrefab() after using it.
        public object LoadFromCache(ObjCachePoolType poolType, string poolKey)
        {
            if (!mDicObjPools.ContainsKey(poolType))
            {
                Debug.LogError(string.Format("ObjCachePoolMgr::LoadPrefab pool type {0} is not defined!", poolType));
                return(null);
            }
            ObjectCachePool dstPool = mDicObjPools[poolType];

            //try load from pool
            GameObject go = dstPool.try_hit_cache(poolKey) as GameObject;

            if (go != null)
            {
                go.transform.SetParent(null, false);
                go.transform.position = new Vector3(0, -1000, 0);
            }
            return(go);
        }
示例#3
0
        //load a prefab from pool, it not found in pool, return null
        //notice: if you got object by this method, you should call RecyclePrefab() after using it.
        public IEnumerator LoadPrefab(string assetPath, ObjCachePoolType poolType, string poolKey, ObjectWrapper prefab)
        {
            if (poolKey == null)
            {
                poolKey = assetPath;
            }
            if (!mDicObjPools.ContainsKey(poolType))
            {
                Debug.LogError(string.Format("ObjCachePoolMgr::LoadPrefab pool type {0} is not defined!", poolType));
                yield break;
            }
            ObjectCachePool dstPool = mDicObjPools[poolType];

            //try load from pool
            GameObject obj = dstPool.try_hit_cache(poolKey) as GameObject;

            if (obj == null)
            {
                PrefabResource pr = new PrefabResource();
                yield return(StartCoroutine(ResourceLoader.Instance.load_prefab(string.Format("Assets/Res/{0}.prefab", assetPath), pr)));

                obj = pr.obj_;
                if (obj == null)
                {
                    yield break;
                }

                PoolGameObject pg = obj.AddComponent <PoolGameObject>();
                pg.poolType = poolType;
                pg.key      = poolKey;
            }
            else
            {
                obj.transform.SetParent(null, false);
                obj.SetActive(true);
            }
            obj.transform.position = new Vector3(0, -1000, 0);
            prefab.obj             = obj;
        }