示例#1
0
        public ResLoadOpertion LoadAssetAsync <T>(string resPath) where T : Object
        {
            ResToAssetBundleCnf abInfo = _mainInfo.GetResToAb(resPath);

            if (abInfo == null)
            {
                return(null);
            }

            AssetBundleDepCnf abDep = _mainInfo.GetDepsInfo(abInfo.PackagePath);

            if (abDep == null)
            {
                return(null);
            }

            foreach (var depInfo in abDep._childRef)
            {
                InternalAsyncLoadPackage(depInfo.Key);
            }

            ResLoadOpertion resLoadOperation = InternalAsyncLoadPackage(abDep.AbName);

            return(resLoadOperation);
        }
示例#2
0
        public void OnUpdate(float dt)
        {
            if (_loader != null)
            {
                _loader.OnUpdate();
            }
            int length = _otherOperation.Count - 1;

            for (int i = length; i >= 0; i--)
            {
                LoadOpertion loadOpertion = _otherOperation[i];
                loadOpertion.OnUpdate();
                if (loadOpertion.IsDone())
                {
                    _otherOperation.RemoveAt(i);
                }
            }

            length = _loadOpertions.Count - 1;
            for (int i = length; i >= 0; i--)
            {
                ResLoadOpertion loadOpertion = _loadOpertions[i];
                loadOpertion.OnUpdate();
                if (!loadOpertion.IsExit())
                {
                    continue;
                }

                _onLoadingRes.RemoveAt(i);
                _loadOpertions.RemoveAt(i);
            }
        }
示例#3
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);
        }
示例#4
0
        // 内置异步加载指定路径的AssetBundle包
        private ResLoadOpertion InternalAsyncLoadPackage(string packagePath)
        {
            AssetBundlePackageCnf packageCnf = _mainInfo.GetPackageCnf(packagePath);

            if (packageCnf == null)
            {
                return(null);
            }

            // 1.已经在缓存中,引用+1
            AssetBundleInfo packageInfo = GetPackageInfo(packagePath);

            if (packageInfo != null)
            {
                AssetBundleCompleteLoadOperation operation = new AssetBundleCompleteLoadOperation(packageInfo);
                operation.OnUpdate();
                return(operation);
            }

            // 2.如果已经在加载中,返回已经在加载中的结果
            int index = _onLoadingAbPackage.IndexOf(packagePath);

            if (index >= 0)
            {
                ResLoadOpertion loadOperation = _onLoadingRequest[index];
                return(loadOperation);
            }

            // 3.如果在等待中,返回等待中加载中的结果
            index = _onWaitAbPackage.IndexOf(packagePath);
            if (index >= 0)
            {
                ResLoadOpertion loadOperation = _waitToLoadRequest[index];
                return(loadOperation);
            }

            // 4得到Ab的包消息,并且添加到等待列表中
            AssetBundleAsyncLoadOpertion packageOpertion = new AssetBundleAsyncLoadOpertion(packageCnf);

            _waitToLoadRequest.Add(packageOpertion);
            _onWaitAbPackage.Add(packagePath);
            return(packageOpertion);
        }
示例#5
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);
            }
        }