private void SetupDownloadOperation(AssetStoreDownloadOperation operation) { m_DownloadOperations[operation.packageUniqueId] = operation; operation.onOperationError += (op, error) => onDownloadError?.Invoke(op, error); operation.onOperationFinalized += (op) => onDownloadFinalized?.Invoke(op); operation.onOperationProgress += (op) => onDownloadProgress?.Invoke(op); }
// This function will be called by AssetStoreUtils after the download delegate registration // AssetStoreUtils.instance.RegisterDownloadDelegate public void OnDownloadProgress(string downloadId, string message, ulong bytes, ulong total) { // The download unique id we receive from the A$ download callback could be in the format of // `123456` or `content__123456` (depending on where the download starts). // therefore we have a progress that makes sure everything is in the format of `123456`. var productId = downloadId; if (downloadId.StartsWith(AssetStoreDownloadOperation.k_AssetStoreDownloadPrefix)) { productId = downloadId.Substring(AssetStoreDownloadOperation.k_AssetStoreDownloadPrefix.Length); } // `GetDownloadOperation` could return null when the user starts the download in the legacy `Asset Store` window // in those cases, we create a download operation to track it var operation = GetDownloadOperation(productId); if (operation == null) { operation = new AssetStoreDownloadOperation(productId); SetupDownloadOperation(operation); } operation.OnDownloadProgress(message, bytes, total); if (!operation.isInProgress) { RemoveDownloadOperation(productId); } }
public void Download(string productId) { var operation = GetDownloadOperation(productId); if (operation?.isInProgress ?? false) { return; } operation = new AssetStoreDownloadOperation(productId); SetupDownloadOperation(operation); operation.Download(); }
public virtual void Download(string productId) { var operation = GetDownloadOperation(productId); if (operation?.isInProgress ?? false) { return; } operation = new AssetStoreDownloadOperation(m_AssetStoreUtils, m_AssetStoreRestAPI, productId); SetupDownloadOperation(operation); operation.Download(false); }