public DownloadSizeAsyncOperation(IList <string> assetPacks)
        {
            assetPackSizeOperations = new List <PlayAsyncOperation <long, AssetDeliveryErrorCode> >();
            foreach (string assetPack in assetPacks)
            {
                // check if the asset pack was already downloaded either during install or previous launch.
                if (PlayAssetDelivery.IsDownloaded(assetPack))
                {
                    Debug.LogFormat("[{0}] Assetpack={1} Already downloaded", nameof(DownloadSizeAsyncOperation), assetPack);
                    continue;
                }
                PlayAsyncOperation <long, AssetDeliveryErrorCode> sizeOperation = PlayAssetDelivery.GetDownloadSize(assetPack);
                assetPackSizeOperations.Add(sizeOperation);
                if (sizeOperation.IsDone)
                {
                    OnGetPackDownloadSize(sizeOperation);
                    continue;
                }
                sizeOperation.Completed += OnGetPackDownloadSize;
            }

            // No Asset packs needed to be updated.
            if (assetPackSizeOperations.Count == 0)
            {
                Complete(AsyncOperationStatus.Succeeded);
            }
        }
        /// <summary>
        /// Load "sceneassetbundle" and "textureassetbundle" and start the scene.
        /// </summary>
        private IEnumerator DownloadAssetBundles()
        {
            Debug.Log("Starting to retrieve AssetBundle");

            // Asset bundle with a scene:
            var sceneAssetBundleRequest = PlayAssetDelivery.RetrieveAssetBundleAsync("sceneassetbundle");

            // Asset bundle with some textures:
            var textureAssetBundleRequest = PlayAssetDelivery.RetrieveAssetBundleAsync("textureassetbundle");

            while (!sceneAssetBundleRequest.IsDone && !textureAssetBundleRequest.IsDone)
            {
                yield return(null);
            }

            if (sceneAssetBundleRequest.Error != AssetDeliveryErrorCode.NoError)
            {
                Debug.LogErrorFormat("Couldn't load sceneassetbundle: {0}", sceneAssetBundleRequest.Error);
                yield break;
            }

            if (textureAssetBundleRequest.Error != AssetDeliveryErrorCode.NoError)
            {
                Debug.LogErrorFormat("Couldn't load textureassetbundle: {0}", textureAssetBundleRequest.Error);
                yield break;
            }

            var sceneToLoad = sceneAssetBundleRequest.AssetBundle.GetAllScenePaths()[0];

            SceneManager.LoadScene(sceneToLoad);
        }
 private void SetInitialStatus()
 {
     ColorTint.color = NeutralColor;
     LoadingBar.SetProgress(0f);
     ShowButtons(RetrieveAssetBundleButton);
     StatusText.text = PlayAssetDelivery.IsDownloaded(AssetBundleName)
         ? AssetDeliveryStatus.Available.ToString()
         : AssetDeliveryStatus.Pending.ToString();
 }
Beispiel #4
0
 protected override void BeginOperationImpl(string assetPackName)
 {
     Debug.LogFormat("[{0}.{1}] assetPackName={2}", nameof(AssetPackAsyncAssetBundleResourceHandler), nameof(BeginOperation), assetPackName);
     playAssetPackRequest = PlayAssetDelivery.RetrieveAssetPackAsync(assetPackName);
     if (playAssetPackRequest.IsDone)
     {
         OnPlayAssetPackRequestCompleted(assetPackName, playAssetPackRequest);
         return;
     }
     playAssetPackRequest.Completed += request => OnPlayAssetPackRequestCompleted(assetPackName, request);
 }
Beispiel #5
0
 public void StartDownload()
 {
     if (isSingleAssetBundlePack && assetBundleRequest == null)
     {
         assetBundleRequest = PlayAssetDelivery.RetrieveAssetBundleAsync(
             assetPackName);
     }
     else if (!isSingleAssetBundlePack && assetPackRequest == null)
     {
         assetPackRequest = PlayAssetDelivery.RetrieveAssetPackAsync(
             assetPackName);
     }
 }
Beispiel #6
0
    public bool IsDownloaded()
    {
        bool isDownloaded;

        if (isSingleAssetBundlePack && assetBundleRequest != null)
        {
            isDownloaded = assetBundleRequest.IsDone;
        }
        else
        {
            isDownloaded = PlayAssetDelivery.IsDownloaded(assetPackName);
        }
        return(isDownloaded);
    }
        protected override void BeginOperationImpl(string assetPackName)
        {
            Debug.LogFormat("[{0}.{1}] assetPackName={2}", nameof(AssetPackSyncAssetBundleResourceHandler), nameof(BeginOperation), assetPackName);
            playAssetPackRequest = PlayAssetDelivery.RetrieveAssetPackAsync(assetPackName);
            if (!playAssetPackRequest.IsDone)
            {
                CompleteOperation(this, $"Asset Pack was not retrieved Synchronously: '{assetPackName}'.");
                return;
            }
            var assetLocation = playAssetPackRequest.GetAssetLocation(assetPackName);
            var assetBundle   = AssetBundle.LoadFromFile(assetLocation.Path, 0, assetLocation.Offset);

            CompleteOperation(this, assetBundle);
        }
        /// <summary>
        /// Remove all asset packs specified in <see cref="Assets"/>.
        /// </summary>
        public void ButtonEventRemovePacks()
        {
            // Defensive check. In practice this should never occur because the remove button is only shown once the
            // batch request is initialized.
            if (_batchRequest == null)
            {
                return;
            }

            foreach (var asset in Assets)
            {
                PlayAssetDelivery.RemoveAssetPack(asset.AssetPackName);
            }

            SetInitialStatus();
        }
Beispiel #9
0
        public void ButtonEventRemoveAssetBundle()
        {
            var removeOperation = PlayAssetDelivery.RemoveAssetPack(AssetBundleName);

            removeOperation.Completed += (operation) =>
            {
                if (operation.Error != AssetDeliveryErrorCode.NoError)
                {
                    Debug.LogErrorFormat("Error removing AssetBundle {0}: {1}", AssetBundleName, operation.Error);
                    return;
                }

                SetInitialStatus();
                UnloadAssetBundle();
            };
        }
        private IEnumerator DownloadAssetPackCo()
        {
#if PLAY_ASSET_DELIVERY_EXPERIMENTAL
            _request           = PlayAssetDelivery.RetrieveAssetPackAsync(AssetPackName);
            _requestInProgress = true;

            while (!_request.IsDone)
            {
                if (_request.Status == AssetDeliveryStatus.WaitingForWifi)
                {
                    // Wait until user has confirmed or cancelled the dialog.
                    var asyncOperation = PlayAssetDelivery.ShowCellularDataConfirmation();
                    yield return(asyncOperation);

                    if (asyncOperation.Error != AssetDeliveryErrorCode.NoError ||
                        asyncOperation.GetResult() != ConfirmationDialogResult.Accepted)
                    {
                        // Provide a button to re-show the dialog in case user changes their mind.
                        Display.SetStatus(_request.Status, _request.Error);
                    }

                    yield return(new WaitUntil(() => _request.Status != AssetDeliveryStatus.WaitingForWifi));
                }

                Display.SetProgress(_request.DownloadProgress);
                Display.SetStatus(_request.Status, _request.Error);

                yield return(null);
            }

            Display.SetProgress(_request.DownloadProgress);
            Display.SetStatus(_request.Status, _request.Error);

            if (_request.Error != AssetDeliveryErrorCode.NoError)
            {
                Debug.LogErrorFormat("Couldn't load asset pack: {0}", _request.Error);
                _request = null;
            }

            _requestInProgress = false;
#else
            // Assign values to avoid unassigned variable warning.
            _request           = null;
            _requestInProgress = false;
            throw new Exception("Experimental Play Asset Delivery methods are disabled.");
#endif
        }
Beispiel #11
0
    private void StartAssetPackSizeQuery()
    {
        var getSizeOperation = PlayAssetDelivery.GetDownloadSize(assetPackName);

        getSizeOperation.Completed += (operation) =>
        {
            if (operation.Error != AssetDeliveryErrorCode.NoError)
            {
                Debug.LogErrorFormat("Error getting download size for {0}: {1}",
                                     assetPackName, operation.Error);
                return;
            }

            assetPackSize        = operation.GetResult();
            isAssetPackSizeValid = true;
        };
    }
Beispiel #12
0
        private void BeginOperation(string assetPackName)
        {
            Debug.LogFormat("[{0}.{1}] assetPackName={2}", nameof(AssetPackBundleSyncResource), nameof(BeginOperation), assetPackName);
            playAssetPackRequest = PlayAssetDelivery.RetrieveAssetPackAsync(assetPackName);
            Exception exception = null;

            if (playAssetPackRequest.IsDone)
            {
                var assetLocation = playAssetPackRequest.GetAssetLocation(assetPackName);
                assetBundle = AssetBundle.LoadFromFile(assetLocation.Path, /* crc= */ 0, assetLocation.Offset);
            }
            else
            {
                exception = new Exception($"Asset Pack was not retrieved Synchronously: '{assetPackName}'.");
            }
            CompletedEvent?.Invoke(this, assetBundle != null, exception);
        }
        private void SetInitialStatus()
        {
            Display.ShowButtons(RetrieveAssetPackBatchButton);

            var allDownloaded = true;

            foreach (var asset in Assets)
            {
                if (!PlayAssetDelivery.IsDownloaded(asset.AssetPackName))
                {
                    allDownloaded = false;
                    break;
                }
            }

            Display.SetInitialStatus(allDownloaded);
        }
        private void DisplayDownloadSize()
        {
            var getSizeOperation = PlayAssetDelivery.GetDownloadSize(AssetBundleName);

            getSizeOperation.Completed += (operation) =>
            {
                if (operation.Error != AssetDeliveryErrorCode.NoError)
                {
                    Debug.LogErrorFormat("Error getting download size for {0}: {1}",
                                         AssetBundleName, operation.Error);
                    return;
                }

                IsInitialized = true;
                NameText.text = string.Format("{0} : {1}", AssetBundleName, FormatSize(operation.GetResult()));
            };
        }
        private IEnumerator CoLoadAssetPackBatch()
        {
#if PLAY_ASSET_DELIVERY_EXPERIMENTAL
            var assetPackNames = Assets.Select(a => a.AssetPackName).Distinct().ToList();
            _batchRequest      = PlayAssetDelivery.RetrieveAssetPackBatchAsync(assetPackNames);
            _requestInProgress = true;

            while (!_batchRequest.IsDone)
            {
                var totalProgress = 0f;
                foreach (var request in _batchRequest.Requests.Values)
                {
                    totalProgress += request.DownloadProgress;
                }

                Display.SetProgress(totalProgress / _batchRequest.Requests.Count);
                Display.SetStatus(AssetDeliveryStatus.Retrieving, AssetDeliveryErrorCode.NoError);
                yield return(null);
            }

            var allSucceeded = true;
            foreach (var request in _batchRequest.Requests.Values)
            {
                if (request.Error != AssetDeliveryErrorCode.NoError)
                {
                    Display.SetStatus(request.Status, request.Error);
                    allSucceeded = false;
                    break;
                }
            }

            if (allSucceeded)
            {
                Display.SetProgress(1f);
                Display.SetStatus(AssetDeliveryStatus.Available, AssetDeliveryErrorCode.NoError);
            }

            _requestInProgress = false;
#else
            // Assign values to avoid unassigned variable warning.
            _batchRequest      = null;
            _requestInProgress = false;
            throw new Exception("Experimental Play Asset Delivery methods are disabled.");
#endif
        }
Beispiel #16
0
    IEnumerator AskForCellularDataPermission()
    {
        var asyncOperation = PlayAssetDelivery.ShowCellularDataConfirmation();

        // Wait until user has confirmed or cancelled the dialog.
        yield return(asyncOperation);

        bool permissionAllow = asyncOperation.Error ==
                               AssetDeliveryErrorCode.NoError && asyncOperation.GetResult() ==
                               ConfirmationDialogResult.Accepted;

        if (permissionAllow)
        {
            yield return(new WaitUntil(() =>
                                       GetStatus() != AssetDeliveryStatus.WaitingForWifi));
        }
        didApproveCellularData       = permissionAllow;
        isCellularConfirmationActive = false;
    }
        private IEnumerator DownloadAssetPackCo()
        {
            _request           = PlayAssetDelivery.RetrieveAssetPackAsync(AssetPackName);
            _requestInProgress = true;

            while (!_request.IsDone)
            {
                if (_request.Status == AssetDeliveryStatus.WaitingForWifi)
                {
                    // Wait until user has confirmed or cancelled the dialog.
                    var asyncOperation = PlayAssetDelivery.ShowCellularDataConfirmation();
                    yield return(asyncOperation);

                    if (asyncOperation.Error != AssetDeliveryErrorCode.NoError ||
                        asyncOperation.GetResult() != ConfirmationDialogResult.Accepted)
                    {
                        // Provide a button to re-show the dialog in case user changes their mind.
                        Display.SetStatus(_request.Status, _request.Error);
                    }

                    yield return(new WaitUntil(() => _request.Status != AssetDeliveryStatus.WaitingForWifi));
                }

                Display.SetProgress(_request.DownloadProgress);
                Display.SetStatus(_request.Status, _request.Error);

                yield return(null);
            }

            Display.SetProgress(_request.DownloadProgress);
            Display.SetStatus(_request.Status, _request.Error);

            if (_request.Error != AssetDeliveryErrorCode.NoError)
            {
                Debug.LogErrorFormat("Couldn't load asset pack: {0}", _request.Error);
                _request = null;
            }

            _requestInProgress = false;
        }
        private IEnumerator CoLoadAssetPackBatch()
        {
            var assetPackNames = Assets.Select(a => a.AssetPackName).Distinct().ToList();

            _batchRequest      = PlayAssetDelivery.RetrieveAssetPackBatchAsync(assetPackNames);
            _requestInProgress = true;

            while (!_batchRequest.IsDone)
            {
                var totalProgress = 0f;
                foreach (var request in _batchRequest.Requests.Values)
                {
                    totalProgress += request.DownloadProgress;
                }

                Display.SetProgress(totalProgress / _batchRequest.Requests.Count);
                Display.SetStatus(AssetDeliveryStatus.Retrieving, AssetDeliveryErrorCode.NoError);
                yield return(null);
            }

            var allSucceeded = true;

            foreach (var request in _batchRequest.Requests.Values)
            {
                if (request.Error != AssetDeliveryErrorCode.NoError)
                {
                    Display.SetStatus(request.Status, request.Error);
                    allSucceeded = false;
                    break;
                }
            }

            if (allSucceeded)
            {
                Display.SetProgress(1f);
                Display.SetStatus(AssetDeliveryStatus.Available, AssetDeliveryErrorCode.NoError);
            }

            _requestInProgress = false;
        }
Beispiel #19
0
 private void SetInitialStatus()
 {
     Display.ShowButtons(RetrieveAssetBundleButton);
     Display.SetInitialStatus(PlayAssetDelivery.IsDownloaded(AssetBundleName));
 }
Beispiel #20
0
 public void ButtonEventShowCellularDialog()
 {
     PlayAssetDelivery.ShowCellularDataConfirmation();
 }
 private void BeginOperation(string assetPackName)
 {
     Debug.LogFormat("[{0}.{1}] assetPackName={2}", nameof(AssetPackBundleAsyncResource), nameof(BeginOperation), assetPackName);
     playAssetPackRequest            = PlayAssetDelivery.RetrieveAssetPackAsync(assetPackName);
     playAssetPackRequest.Completed += request => OnPlayAssetPackRequestCompleted(assetPackName, request);
 }