Exemplo n.º 1
0
        public virtual bool Release(T obj)
        {
            if (!_usingObjects.Contains(obj))
            {
                throw new Exception(string.Format("{0} CachePool中不包含实例{1}对象", Name, obj.name));
            }

            _usingObjects.Remove(obj);
            _cache.Release(obj);
            _lastUseTime = Time.time;
            if (OnRelease != null)
            {
                OnRelease(obj);
            }
            return(true);
        }
Exemplo n.º 2
0
 public void Put(GameObject effect)
 {
     if (usingeffects.Contains(effect))
     {
         effectpool.Release(effect);
         usingeffects.Remove(effect);
         lastusetime = Time.time;
         //Util.LogColor("white", "EffectPoolItem:Put " + path + Time.time);
     }
 }
Exemplo n.º 3
0
        private void DoDelayTasks()
        {
            if (_delayAssetLoadTask.Count > 0)
            {
                while (_delayAssetLoadTask.Count > 0 && _currentTaskCount < MaxTaskCount)
                {
                    AssetLoadTask task = _delayAssetLoadTask.Dequeue();
                    DoTask(task);
                }
            }
            if (_delayLoadTask.Count > 0)
            {
                var maxLoadTime = 0.02f;
                var startTime   = Time.realtimeSinceStartup;
                while (_delayLoadTask.Count > 0 && Time.realtimeSinceStartup - startTime < maxLoadTime)
                {
                    CompleteTask loadTask = _delayLoadTask.Dequeue();
                    var          task     = loadTask.task;
                    var          bundle   = loadTask.bundle;

                    Object obj = null;
                    if (bundle != null)
                    {
                        if (!bundle.isStreamedSceneAssetBundle)
                        {
                            var objs = bundle.LoadAllAssets();
                            if (objs.Length > 0)
                            {
                                obj = objs[0];
                            }
                            if (obj == null)
                            {
                                Debug.LogErrorFormat("LoadBundle: {0} ! No Assets in Bundle!", task.path);
                            }
                        }
                    }
                    OnAseetsLoaded(task, bundle, obj);
                    _loadTaskPool.Release(loadTask);
                }
            }
        }
Exemplo n.º 4
0
        //Asset加载完毕,可能是依赖资源,也可能是主资源
        private void OnAseetsLoaded(AssetLoadTask task, AssetBundle ab, Object obj)
        {
            if (_assetDependencies.ContainsKey(task.path))
            {
                RemoveRefCount(task.path);
            }

            _loadingFiles.Remove(task.path);
            _loadingTasks.Remove(task.id);

            //主资源加载完毕
            if (task.actions != null && task.parentTaskIds == null)
            {
                Delegate[] delegates = task.actions.GetInvocationList();
                foreach (var dele in delegates)
                {
                    var action = (Action <Object>)dele;
                    try
                    {
                        if ((task.loadType & (int)ResourceLoadType.ReturnAssetBundle) > 0)
                        {
                            action(ab);
                        }
                        else
                        {
                            action(obj);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogErrorFormat("Load Bundle {0} DoAction Exception: {1}", task.path, e);
                    }
                }
            }

            //缓存加载的资源对象[非AB]
            if (ab != null && task.parentTaskIds == null)
            {
                if ((task.loadType & (int)ResourceLoadType.Persistent) > 0)
                {
                    _persistantObjects[task.path] = obj;
                    if ((task.loadType & (int)ResourceLoadType.UnLoad) > 0)
                    {
                        ab.Unload(false);
                    }
                }
                else
                {
                    if ((task.loadType & (int)ResourceLoadType.Cache) > 0)
                    {
                        var cacheObject = new CacheObject
                        {
                            lastUseTime = Time.realtimeSinceStartup,
                            obj         = obj
                        };

                        _cacheObjects[task.path] = cacheObject;
                    }
                    if ((task.loadType & (int)ResourceLoadType.ReturnAssetBundle) == 0)
                    {
                        ab.Unload(false);
                    }
                }
            }

            //依赖资源加载完毕
            if (task.parentTaskIds != null)
            {
                _assetBundlesObj[task.path] = ab;
                for (int i = 0; i < task.parentTaskIds.Count; ++i)
                {
                    uint          taskid = task.parentTaskIds[i];
                    AssetLoadTask pt     = null;
                    if (_loadingTasks.TryGetValue(taskid, out pt))
                    {
                        pt.loadedDependenciesCount += 1;
                        if (pt.loadedDependenciesCount >= pt.dependencies.Count)
                        {
                            DoTask(pt);
                        }
                    }
                }
            }

            task.Reset();
            _assetLoadTaskPool.Release(task);
        }