// 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.AppUpdate
{
///
/// A CustomYieldInstruction
/// used to monitor an ongoing in-app update.
///
public abstract class AppUpdateRequest : CustomYieldInstruction
{
///
/// Event indicating that the request has 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 { };
///
/// Returns true if this request has finished, false otherwise.
///
public bool IsDone { get; protected set; }
///
/// Returns the status of this request, for example .
/// This will be if an error occurred.
///
public AppUpdateStatus Status { get; protected set; }
///
/// Returns the error that prevented this request from completing successfully. This will be
/// in the case of a pending request or a successful update.
///
public AppUpdateErrorCode Error { get; protected set; }
///
/// Returns a value between 0 and 1 indicating the overall download progress of a flexible update flow.
/// Note: If this value is 1, it doesn't mean that the update has completed, only that the
/// Downloading stage has finished.
///
/// Note: always returns 0 for an immediate update flow.
///
public float DownloadProgress { get; protected set; }
///
/// Returns the total number of bytes already downloaded for the update.
///
public ulong BytesDownloaded { get; protected set; }
///
/// Returns the total number of bytes to download for the update.
///
public ulong TotalBytesToDownload { get; protected set; }
///
/// Implements the CustomYieldInstruction.keepWaiting
/// property so that this request can be yielded on in a coroutine.
///
public override bool keepWaiting
{
get { return !IsDone; }
}
///
/// Invokes the event.
///
protected void InvokeCompletedEvent()
{
Completed.Invoke(this);
}
}
}