Beispiel #1
0
        private IEnumerator InternalLoadAssetAsync <T>(string resPath, Action <T> callback) where T : Object
        {
            // 1.得到路径 检测是否处于加载中
            if (_onLoadingRes.Contains(resPath))
            {
                // 3.等待加载 或者之类来一个ResWaitOpetion来确认
                // TODO Factory
                ResWaitLoadOpertion resWaitLoad = new ResWaitLoadOpertion(resPath, TIME_OUT);
                _otherOperation.Add(resWaitLoad);
                yield return(resWaitLoad);

                if (!ContainsRes(resPath))
                {
                    ResLog.Error("ResLoader InternalLoadAssetAsync 超时请求:[{0}]", resPath);
                    yield break;
                }
            }
            else
            {
                if (!CanAsynLoad())
                {
                    yield return(_maxOperationLoad);
                }

                _currAsyncCount++;
                // 4.请求异步加载
                ResLoadOpertion loadOpertion = _loader.LoadAssetAsync <T>(resPath);
                ResLog.Assert(loadOpertion != null, "ResLoader InternalLoadAssetAsync 异步请求为空.加载路径:[{0}]", resPath);
                if (loadOpertion == null)
                {
                    yield break;
                }
                // TODO 请求的地址是和加载的路径是不一样的东西
                _onLoadingRes.Add(resPath);
                _loadOpertions.Add(loadOpertion);
                // 等待加载完成
                if (!loadOpertion.IsDone())
                {
                    yield return(loadOpertion);
                }
                I_ObjectInfo objectInfo = loadOpertion.GetAsset <T>(resPath);
                // 6.卸载请求信息
                loadOpertion.UnloadRequest();
                // 7.t推送到内存中
                PushAssetToCache(objectInfo);
                _currAsyncCount--;
            }
            bool result = CallbackByCache(resPath, callback);

            if (!result)
            {
                ResLog.Error("加载完成...但出现资源错误,path:[{0}]", resPath);
            }
            yield return(null);
        }
Beispiel #2
0
        public void OnUpdate()
        {
            // 1.更新请求
            int length = _onLoadingRequest.Count - 1;

            for (int i = length; i >= 0; i--)
            {
                ResLoadOpertion opertion = _onLoadingRequest[i];
                opertion.OnUpdate();
                if (opertion.IsExit())
                {
                    opertion.UnloadRequest();
                    _onLoadingRequest.RemoveAt(i);
                    _onLoadingAbPackage.RemoveAt(i);
                }
            }

            // 检测新的内容
            int removeCount = 0;

            length = _waitToLoadRequest.Count;
            for (int i = 0; i < length; i++)
            {
                if (_onLoadingRequest.Count >= _maxLoadingCount)
                {
                    break;
                }
                ResLoadOpertion loadOpertion = _waitToLoadRequest[i];
                removeCount++;
                _onLoadingRequest.Add(loadOpertion);
                _onLoadingAbPackage.Add(loadOpertion.RequestResPath);
            }
            if (removeCount > 0)
            {
                _waitToLoadRequest.RemoveRange(0, removeCount);
                _onWaitAbPackage.RemoveRange(0, removeCount);
            }
        }