Ejemplo n.º 1
0
 private void _OnCacheFull()
 {
     if (m_deSpawnCount > ResourceConfig.MAX_POOL_COUNT)
     {
         ResourcePool first = _GetCacheFirst();
         if (first != null)
         {
             m_deSpawnCount -= first.GetObjectCount();
             first.Clear(false);
             _RemoveCacheValue(first.Id);
         }
     }
 }
Ejemplo n.º 2
0
        public void Merge(ResourcePool data)
        {
            Log.Assert(data.m_asset == this.m_asset);

            MergeRefCount(data);

            foreach (var gameObject in data.m_objectList)
            {
                m_objectList.AddLast(gameObject);
            }
            data.m_objectList.Clear();
            data.Clear(true);
        }
Ejemplo n.º 3
0
        private void _AddCacheValue(ResourcePool resourcePool)
        {
            LinkedListNode <ResourcePool> lnode;

            if (m_cacheMap.TryGetValue(resourcePool.Id, out lnode))
            {
                m_lruList.Remove(lnode);
                m_cacheMap.Remove(resourcePool.Id);
            }

            LinkedListNode <ResourcePool> node = new LinkedListNode <ResourcePool>(resourcePool);

            m_lruList.AddLast(node);
            m_cacheMap.Add(resourcePool.Id, node);
        }
Ejemplo n.º 4
0
        private ResourcePool _AddResourcePool(ResourcePool resourcePool)
        {
            ResourcePool existedPool = null;

            if (m_pathHash2Pool.TryGetValue(resourcePool.Id, out existedPool))
            {
                m_deSpawnCount += resourcePool.GetObjectCount();
                existedPool.Merge(resourcePool);
                return(existedPool);
            }

            m_pathHash2Pool.Add(resourcePool.Id, resourcePool);

            return(resourcePool);
        }
Ejemplo n.º 5
0
        private void _OnRequestDone(RequestBase <ResourcePool> requestBase)
        {
            ResourceSpawnRequest request = requestBase as ResourceSpawnRequest;

            if (request == null)
            {
                Log.Error("[ResourcePoolManager]Invalid request.");
                return;
            }

            ResourcePool resourcePool = request.asset as ResourcePool;

            if (resourcePool == null)
            {
                Log.Error("[ResourcePoolManager]Invalid resource pool.");
                return;
            }

            _AddResourcePool(resourcePool);

            foreach (var spawnHandle in request.spawnHandleList)
            {
                if (!spawnHandle.success)
                {
                    continue;
                }

                int spawnID = spawnHandle.spawnID;
                if (m_spawnID2PathHash.ContainsKey(spawnID))
                {
                    GameObject gameObject     = spawnHandle.gameObject;
                    string     gameObjectName = gameObject != null ? gameObject.name : "Unknown";
                    Log.ErrorFormat("[ResourcePoolManager]Duplicated spawn id for gameObject({0})", gameObjectName);
                    if (Application.isPlaying)
                    {
                        GameObject.Destroy(gameObject);
                    }
                    else
                    {
                        GameObject.DestroyImmediate(gameObject);
                    }
                    continue;
                }

                m_spawnID2PathHash[spawnID] = resourcePool.Id;
            }
        }
Ejemplo n.º 6
0
        public void UnloadUnusedPool()
        {
            foreach (var iterator in m_pathHash2Pool)
            {
                ResourcePool resourcePool = iterator.Value;
                if (resourcePool == null || resourcePool.IsRefZero())
                {
                    m_clearList.Add(iterator.Key);
                }
            }

            for (int i = 0; i < m_clearList.Count; ++i)
            {
                _ClearResourcePool(m_clearList[i]);
            }
            m_clearList.Clear();
        }
Ejemplo n.º 7
0
        private void _ClearResourcePool(ulong pathHash)
        {
            ResourcePool resourcePool = null;

            if (!m_pathHash2Pool.TryGetValue(pathHash, out resourcePool))
            {
                return;
            }

            m_pathHash2Pool.Remove(pathHash);
            if (resourcePool != null)
            {
                int count = resourcePool.GetObjectCount();
                if (count > 0)
                {
                    m_deSpawnCount -= count;
                    _RemoveCacheValue(resourcePool.Id);
                }
                resourcePool.Clear(true);
            }
        }