private PlayAssetBundleRequestImpl CreateAssetBundleRequest(string assetBundleName)
        {
            var request = new PlayAssetBundleRequestImpl(assetBundleName, _assetPackManager, _requestRepository);

            _requestRepository.AddRequest(request);
            request.Completed += (req) => _requestRepository.RemoveRequest(assetBundleName);
            return(request);
        }
        private void UpdateRequest(
            PlayAssetBundleRequestImpl request,
            AssetPackState newState,
            int errorCode)
        {
            if (request.IsDone)
            {
                // Ignore pack state updates associated with completed requests.
                return;
            }

            var assetDeliveryErrorCode = PlayCoreTranslator.TranslatePlayCoreErrorCode(errorCode);

            if (assetDeliveryErrorCode != AssetDeliveryErrorCode.NoError)
            {
                request.OnErrorOccured(assetDeliveryErrorCode);
                return;
            }

            if (newState.Status == PlayCoreTranslator.AssetPackStatus.Canceled)
            {
                request.OnErrorOccured(AssetDeliveryErrorCode.Canceled);
                return;
            }

            if (newState.Status == PlayCoreTranslator.AssetPackStatus.Completed)
            {
                var isRequestLoadingAssetBundle = _loadingCoroutinesByName.ContainsKey(request.MainAssetBundleName);
                if (!isRequestLoadingAssetBundle)
                {
                    var startedSuccessfully = StartLoadingAssetBundle(request);
                    if (!startedSuccessfully)
                    {
                        request.OnErrorOccured(AssetDeliveryErrorCode.AssetBundleLoadingError);
                        return;
                    }
                }

                request.OnLoadingStarted();
                return;
            }

            request.UpdateState(PlayCoreTranslator.TranslatePlayCorePackStatus(newState.Status),
                                newState.BytesDownloaded,
                                newState.TotalBytesToDownload);
        }
        private bool StartLoadingAssetBundle(PlayAssetBundleRequestImpl request)
        {
            var assetLocation = GetAssetLocation(request.MainAssetBundleName);

            if (assetLocation == null)
            {
                return(false);
            }

            var loadingCo =
                _updateHandler.StartCoroutine(CoLoadAssetBundle(
                                                  request.MainAssetBundleName,
                                                  assetLocation.Path,
                                                  assetLocation.Offset));

            _loadingCoroutinesByName.Add(request.MainAssetBundleName, loadingCo);
            return(true);
        }
 public bool TryGetRequest(string name, out PlayAssetBundleRequestImpl request)
 {
     return(_requestsByName.TryGetValue(name, out request));
 }
 public void AddRequest(PlayAssetBundleRequestImpl request)
 {
     _requestsByName.Add(request.MainAssetBundleName, request);
 }
Пример #6
0
 public void AddAssetBundleRequest(PlayAssetBundleRequestImpl assetBundleRequest)
 {
     AddRequest(assetBundleRequest.PackRequest);
     _assetBundleRequestsByName.Add(assetBundleRequest.PackRequest.AssetPackName, assetBundleRequest);
 }