Esempio n. 1
0
        internal PlayAsyncOperation <long, AssetDeliveryErrorCode> GetDownloadSizeInternal(string assetBundleName)
        {
            var operation = new AssetDeliveryAsyncOperation <long>();

            if (IsInstallTimeAssetBundle(assetBundleName))
            {
                operation.SetResult(0L);
                return(operation);
            }

            var task = _assetPackManager.GetPackStates(assetBundleName);

            task.RegisterOnSuccessCallback(javaPackState =>
            {
                var assetPacks = new AssetPackStates(javaPackState);
                operation.SetResult(assetPacks.TotalBytes);
                task.Dispose();
            });
            task.RegisterOnFailureCallback((message, errorCode) =>
            {
                operation.SetError(PlayCoreTranslator.TranslatePlayCoreErrorCode(errorCode));
                task.Dispose();
            });
            return(operation);
        }
Esempio n. 2
0
        private void UpdateRequest(PlayAssetPackRequestImpl 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;
            }

            request.UpdateState(PlayCoreTranslator.TranslatePlayCorePackStatus(newState.Status),
                                newState.BytesDownloaded,
                                newState.TotalBytesToDownload);
        }
        internal PlayAssetBundleRequest RetrieveAssetBundleAsyncInternal(string assetBundleName)
        {
            if (_requestRepository.ContainsRequest(assetBundleName))
            {
                throw new ArgumentException(string.Format("There is already an active request for AssetBundle: {0}",
                                                          assetBundleName));
            }

            var request = CreateAssetBundleRequest(assetBundleName);

            if (IsDownloaded(assetBundleName))
            {
                StartLoadingAssetBundle(request);
                request.OnLoadingStarted();
            }
            else
            {
                var fetchTask = _assetPackManager.Fetch(assetBundleName);
                fetchTask.RegisterOnSuccessCallback(javaPackStates =>
                {
                    request.OnInitializedInPlayCore();
                    fetchTask.Dispose();
                });
                fetchTask.RegisterOnFailureCallback((reason, errorCode) =>
                {
                    Debug.LogErrorFormat("Failed to retrieve AssetBundle {0}: ", reason);
                    request.OnErrorOccured(PlayCoreTranslator.TranslatePlayCoreErrorCode(errorCode));
                    fetchTask.Dispose();
                });
            }

            return(request);
        }
        internal PlayAssetPackBatchRequest RetrieveAssetPackBatchAsyncInternal(IList <string> assetPackNames)
        {
            if (assetPackNames.Count != assetPackNames.Distinct().Count())
            {
                throw new ArgumentException("assetPackNames contains duplicate entries");
            }

            var activePackNames = assetPackNames.Where(name => _requestRepository.ContainsRequest(name)).ToArray();

            if (activePackNames.Length != 0)
            {
                throw new ArgumentException("There are already active requests for asset packs: {0}",
                                            string.Join(", ", activePackNames));
            }

            // A subset of assetPackNames of packs that are not available on disk.
            var unavailableAssetPackNames = new List <string>();
            var requests = new List <PlayAssetPackRequestImpl>();

            foreach (var assetPackName in assetPackNames)
            {
                var request = CreateAssetPackRequest(assetPackName);
                _requestRepository.AddRequest(request);
                request.Completed += req => _requestRepository.RemoveRequest(request.AssetPackName);
                requests.Add(request);

                if (IsDownloaded(assetPackName))
                {
                    request.OnPackAvailable();
                }
                else
                {
                    unavailableAssetPackNames.Add(assetPackName);
                }
            }

            var batchRequest = new PlayAssetPackBatchRequestImpl(requests);
            var fetchTask    = _assetPackManager.Fetch(unavailableAssetPackNames.ToArray());

            fetchTask.RegisterOnSuccessCallback(javaPackStates =>
            {
                batchRequest.OnInitializedInPlayCore();
                fetchTask.Dispose();
            });
            fetchTask.RegisterOnFailureCallback((reason, errorCode) =>
            {
                Debug.LogErrorFormat("Failed to retrieve asset pack batch: {0}", reason);
                batchRequest.OnInitializationErrorOccurred(PlayCoreTranslator.TranslatePlayCoreErrorCode(errorCode));
                fetchTask.Dispose();
            });

            return(batchRequest);
        }
        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);
        }
Esempio n. 6
0
 private void InitiateRequest(PlayAssetPackRequestImpl request)
 {
     if (IsDownloaded(request.AssetPackName))
     {
         request.OnPackAvailable();
     }
     else
     {
         var fetchTask = _assetPackManager.Fetch(request.AssetPackName);
         fetchTask.RegisterOnSuccessCallback(javaPackStates =>
         {
             request.OnInitializedInPlayCore();
             fetchTask.Dispose();
         });
         fetchTask.RegisterOnFailureCallback((reason, errorCode) =>
         {
             Debug.LogErrorFormat("Failed to retrieve asset pack: {0}", reason);
             request.OnErrorOccured(PlayCoreTranslator.TranslatePlayCoreErrorCode(errorCode));
             fetchTask.Dispose();
         });
     }
 }
Esempio n. 7
0
        ShowCellularDataConfirmationInternal()
        {
            var requests = _requestRepository.GetRequestsWithStatus(AssetDeliveryStatus.WaitingForWifi);

            if (requests.Count == 0)
            {
                throw new Exception("There are no active requests waiting for wifi.");
            }

            var task      = _assetPackManager.ShowCellularDataConfirmation();
            var operation = new AssetDeliveryAsyncOperation <ConfirmationDialogResult>();

            task.RegisterOnSuccessCallback(resultCode =>
            {
                operation.SetResult(ConvertToConfirmationDialogResult(resultCode));
                task.Dispose();
            });
            task.RegisterOnFailureCallback((message, errorCode) =>
            {
                operation.SetError(PlayCoreTranslator.TranslatePlayCoreErrorCode(errorCode));
                task.Dispose();
            });
            return(operation);
        }