// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. using System; using System.Collections.Generic; using Google.Play.AssetDelivery.Internal; using Google.Play.Common; namespace Google.Play.AssetDelivery { /// /// Provides methods for retrieving asset packs via the Play Asset Delivery system. /// public static class PlayAssetDelivery { private static PlayAssetDeliveryInternal _instance; private static PlayAssetDeliveryInternal Instance { get { return _instance ?? (_instance = new PlayAssetDeliveryInternal()); } } /// /// Returns whether or not the specified asset pack is available on disk. /// /// The name of the desired asset pack. /// True if the asset pack is available on disk and false if not. public static bool IsDownloaded(string assetPackName) { return Instance.IsDownloaded(assetPackName); } /// /// Starts a to retrieve an asset pack containing only /// the specified AssetBundle. /// Both the AssetBundle and asset pack must share the same name. Downloads the asset pack if /// it isn't already available on disk. /// /// After download, the contained AssetBundle is loaded into memory before the request completes. /// /// The name of the requested AssetBundle. /// A request object used to monitor the asynchronous AssetBundle retrieval. /// /// Thrown if there is already an active request with the specified name. /// public static PlayAssetBundleRequest RetrieveAssetBundleAsync(string assetBundleName) { return Instance.RetrieveAssetBundleAsyncInternal(assetBundleName); } /// /// Starts a to retrieve an asset pack containing only /// the specified AssetBundle. /// Both the AssetBundle and asset pack must share the same name. Downloads the asset pack if /// it isn't already available on disk. /// /// After download, the contained AssetBundle is loaded into memory before the request completes. /// /// The name of the requested AssetBundle. /// /// If true and the specified pack is already installed, /// this method will check for a newer version and download it if available. /// /// A request object used to monitor the asynchronous AssetBundle retrieval. /// /// Thrown if there is already an active request with the specified name. /// public static PlayAssetBundleRequest RetrieveAssetBundleAsync(string assetBundleName, bool updateIfAvailable) { return Instance.RetrieveAssetBundleAsyncInternal(assetBundleName, updateIfAvailable); } /// /// Starts a to retrieve the specified asset pack. /// Downloads the asset pack if it isn't already available on disk. /// /// After download, the assets and/or AssetBundles contained in the asset pack are not /// loaded into memory. To load them see /// or . /// /// The name of the requested asset pack. /// A request object used to monitor the asynchronous asset pack retrieval. public static PlayAssetPackRequest RetrieveAssetPackAsync(string assetPackName) { return Instance.RetrieveAssetPackAsyncInternal(assetPackName); } /// /// Starts a to retrieve the specified asset pack. /// Downloads the asset pack if it isn't already available on disk. /// /// After download, the assets and/or AssetBundles contained in the asset pack are not /// loaded into memory. To load them see /// or . /// /// The name of the requested asset pack. /// /// If true and the specified pack is already installed, /// this method will check for a newer version and download it if available. /// /// A request object used to monitor the asynchronous asset pack retrieval. public static PlayAssetPackRequest RetrieveAssetPackAsync(string assetPackName, bool updateIfAvailable) { return Instance.RetrieveAssetPackAsyncInternal(assetPackName, updateIfAvailable); } /// /// Starts a to retrieve the specified asset packs. /// Downloads the asset packs if they aren't already available on disk. /// /// After download, the assets and/or AssetBundles contained in the asset pack are not /// loaded into memory. To load them use /// or on the values of the /// dictionary. /// /// A list of requested asset packs. /// A request object used to monitor the asynchronous asset pack batch retrieval. /// Throws if assetPackNames contains duplicate entries. public static PlayAssetPackBatchRequest RetrieveAssetPackBatchAsync(IList assetPackNames) { return Instance.RetrieveAssetPackBatchAsyncInternal(assetPackNames); } /// /// Starts a to retrieve the specified asset packs. /// Downloads the asset packs if they aren't already available on disk. /// /// After download, the assets and/or AssetBundles contained in the asset pack are not /// loaded into memory. To load them use /// or on the values of the /// dictionary. /// /// A list of requested asset packs. /// /// If true and any of the specified packs are already installed, /// this method will check for newer versions of them and download them if available. /// /// A request object used to monitor the asynchronous asset pack batch retrieval. /// Throws if assetPackNames contains duplicate entries. public static PlayAssetPackBatchRequest RetrieveAssetPackBatchAsync(IList assetPackNames, bool updateIfAvailable) { return Instance.RetrieveAssetPackBatchAsyncInternal(assetPackNames, updateIfAvailable); } /// /// Starts a PlayAsyncOperation to determine the download size in bytes of the specified asset pack. /// If the specified asset pack's delivery mode is install-time, then the download size will always be 0. /// public static PlayAsyncOperation GetDownloadSize(string assetPackName) { return Instance.GetDownloadSizeInternal(assetPackName); } /// /// Starts a PlayAsyncOperation to gather download information about the specified asset packs. /// This includes download size and information about asset pack updates. /// /// A list of asset packs. /// /// A PlayAsyncOperation with a Dictionary result keyed by asset pack name, /// containing download info about the specified packs. /// public static PlayAsyncOperation, AssetDeliveryErrorCode> GetDownloadInfo(IList assetPackNames) { return Instance.GetDownloadInfoInternal(assetPackNames); } /// /// Starts a PlayAsyncOperation to delete the specified asset pack from internal storage. /// If the specified asset pack is currently being retrieved, this method will not cancel the /// retrieval. If the specified asset pack contains any AssetBundles that are already loaded into /// memory, the AssetBundles will not be unloaded. /// /// /// An async operation object used to monitor the asset pack removal. If the files are deleted /// successfully or if the files don't exist, the returned operation will complete successfully. /// Otherwise, the operation will complete with an error code. /// public static PlayAsyncOperation RemoveAssetPack(string assetPackName) { return Instance.RemoveAssetPackInternal(assetPackName); } /// /// Shows a confirmation dialog for all currently downloading asset packs that are /// . /// If the user accepts the dialog, then those asset packs are downloaded over cellular data. /// /// A is set to if /// the user is currently not on a Wi-Fi connection and the AssetBundle is large or the user has set /// their download preference in the Play Store to only download apps over Wi-Fi. By showing this /// dialog, the app can ask the user if they accept downloading the asset packs over cellular data /// instead of waiting for Wi-Fi. /// /// /// A that completes /// once the dialog has been accepted, denied, or closed. /// public static PlayAsyncOperation ShowCellularDataConfirmation() { return Instance.ShowCellularDataConfirmationInternal(); } /// /// Shows a dialog that asks the user for consent to download packs that are currently in /// either the state or the /// state. /// /// A is set to /// If the download is not able /// to proceed without user consent. By showing this dialog, the app can ask the user if /// they accept downloading the asset packs through Google Play. If the app has not been /// installed by Play, an update may be triggered to ensure that a valid version is /// installed. This will cause the app to restart and all asset requests to be cancelled. /// These assets should be requested again after the app restarts. /// /// A is set to /// if the user is currently not on a Wi-Fi /// connection and the AssetBundle is large or the user has set their download preference in /// the Play Store to only download apps over Wi-Fi. By showing this dialog, the app can ask /// the user if they accept downloading the asset packs over cellular data instead of /// waiting for Wi-Fi. /// /// /// A /// that completes once the dialog has been accepted, denied, or closed. /// public static PlayAsyncOperation ShowConfirmationDialog() { return Instance.ShowConfirmationDialogInternal(); } } }