// 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 UnityEngine;
namespace Google.Play.AssetDelivery
{
///
/// A CustomYieldInstruction
/// used to monitor the asynchronous retrieval of an asset pack containing an AssetBundle.
///
public abstract class PlayAssetBundleRequest : 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 virtual 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 virtual 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 virtual AssetDeliveryStatus Status { get; protected set; }
///
/// The AssetBundle loaded by this request.
/// This corresponds to the AssetBundle name passed into this request.
/// If Status is not , this value is null.
///
public AssetBundle AssetBundle { 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; }
}
///
/// 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);
}
}
}