// Copyright 2020 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 UnityEngine;
namespace Google.Play.AssetDelivery
{
///
/// A CustomYieldInstruction
/// used to monitor the asynchronous retrieval of an asset pack.
///
public abstract class PlayAssetPackRequest : CustomYieldInstruction
{
///
/// Progress between 0 and 1 indicating the overall download progress of this request.
/// Note: If this value is equal to 1, it does not mean that the request has completed,
/// only that the Downloading stage is finished.
///
public float DownloadProgress { get; protected set; }
///
/// The error that prevented this requested from completing successfully.
/// In the case of a successful request, this will always be .
///
public AssetDeliveryErrorCode Error { get; protected set; }
///
/// Returns true if this request is in the or
/// status, false otherwise.
///
public bool IsDone { get; protected set; }
///
/// An enum indicating the status of this request (downloading, downloaded, installed etc.)
/// If the request completed successfully, this value should be .
/// If an error occured, it should be .
///
public AssetDeliveryStatus Status { get; protected set; }
///
/// Event indicating that the request is completed. If an event handler is registered after the operation has
/// completed, and thus after this event has been invoked, then the handler will be called synchronously.
///
public virtual event Action Completed = delegate { };
///
/// Implements the CustomYieldInstruction.keepWaiting
/// property so that this request can be yielded on in a coroutine.
///
public override bool keepWaiting
{
get { return !IsDone; }
}
///
/// Retrieves the location of an asset at the specified path within this asset pack.
///
/// The path within this asset pack pointing to the desired asset.
///
/// An object describing the path, offset and size of a the requested asset file
/// within the asset pack.
///
public abstract AssetLocation GetAssetLocation(string assetPath);
///
/// Loads the AssetBundle located at the specified path within this asset pack.
///
/// The path within this asset pack pointing to the desired AssetBundle.
///
/// An
/// AssetBundleCreateRequest that can be yielded on until the AssetBundle is loaded.
///
public abstract AssetBundleCreateRequest LoadAssetBundleAsync(string assetBundlePath);
///
/// Cancels the request if possible, setting Status to and
/// Error to .
/// If the request is already
/// or , then the request is left unchanged.
///
public abstract void AttemptCancel();
///
/// Invokes the event.
///
protected void InvokeCompletedEvent()
{
Completed.Invoke(this);
}
}
}