/*******************************************************************************
Copyright © 2015-2022 PICO Technology Co., Ltd.All rights reserved.
NOTICE:All information contained herein is, and remains the property of
PICO Technology Co., Ltd. The intellectual and technical concepts
contained herein are proprietary to PICO Technology Co., Ltd. and may be
covered by patents, patents in process, and are protected by trade secret or
copyright law. Dissemination of this information or reproduction of this
material is strictly forbidden unless prior written permission is obtained from
PICO Technology Co., Ltd.
*******************************************************************************/
using System;
using Pico.Platform.Models;
using UnityEngine;
namespace Pico.Platform
{
/**
* \ingroup Platform
*
* Downloadable content (DLC) represents the contents/files such as expansion packs that users can purchase and download, which can help grow your revenue. Each DLC is associated with an add-on and has an individual SKU as its unique identifier. Users must purchase the app before purchasing the DLCs provided in it. DLCs are downloadable in apps only.
*
* DLC enables you to update your app in a more flexible and lightweight way. Once you want to update the content for a published app, you only need to upload new resources such as levels and cosmetics as DLCs on the PICO Developer Platform, but do not need to upload a new build. Users can thereby purchase, download, and experience the latest resources without having to update or reinstall your app.
*/
public static class AssetFileService
{
///
/// Deletes an installed asset file by asset file ID. The corresponding
/// asset file will be removed from the device.
///
/// The ID of the asset file to delete.
///
/// An object containing the asset file ID, asset file name, and a success flag.
///
public static Task DeleteById(ulong assetFileId)
{
if (!CoreService.Initialized)
{
Debug.LogError(CoreService.NotInitializedError);
return null;
}
return new Task(CLIB.ppf_AssetFile_DeleteById(assetFileId));
}
///
/// Deletes an installed asset file by asset file name. The corresponding
/// asset file will be removed from the device.
///
/// The name of the asset file to delete.
///
/// An object containing the asset file ID, asset file name, and a success flag.
///
public static Task DeleteByName(string assetFileName)
{
if (!CoreService.Initialized)
{
Debug.LogError(CoreService.NotInitializedError);
return null;
}
return new Task(CLIB.ppf_AssetFile_DeleteByName(assetFileName));
}
///
/// Downloads an asset file by asset file ID.
///
/// The ID of the asset file to download.
///
/// An object containing the asset file ID and asset file name.
///
/// If the response returns code `0`, the download will start and
/// the system will periodically push information about the download progress.
/// If the user has not purchased the asset file, a non-zero error code will be returned.
///
public static Task DownloadById(ulong assetFileId)
{
if (!CoreService.Initialized)
{
Debug.LogError(CoreService.NotInitializedError);
return null;
}
return new Task(CLIB.ppf_AssetFile_DownloadById(assetFileId));
}
///
/// Downloads an asset file by asset file name.
///
/// The name of the asset file to download.
///
/// An object containing the asset file ID and asset file name.
///
/// If the response returns code `0`, the download will start and
/// the system will periodically push information about the download progress.
/// If the user has not purchased the asset file, a non-zero error code will be returned.
///
public static Task DownloadByName(string assetFileName)
{
if (!CoreService.Initialized)
{
Debug.LogError(CoreService.NotInitializedError);
return null;
}
return new Task(CLIB.ppf_AssetFile_DownloadByName(assetFileName));
}
///
/// Cancels the download of an asset file by asset file ID.
///
///
/// The ID of the asset file to cancel download for.
///
/// An object contains the asset file ID, asset file name, and a success flag.
///
public static Task DownloadCancelById(ulong assetFileId)
{
if (!CoreService.Initialized)
{
Debug.LogError(CoreService.NotInitializedError);
return null;
}
return new Task(CLIB.ppf_AssetFile_DownloadCancelById(assetFileId));
}
///
/// Cancels the download of an asset file by asset file name.
///
///
/// The name of the asset file to cancel download for.
///
/// An object contains the asset file ID, asset file name, and a success flag.
///
public static Task DownloadCancelByName(string assetFileName)
{
if (!CoreService.Initialized)
{
Debug.LogError(CoreService.NotInitializedError);
return null;
}
return new Task(CLIB.ppf_AssetFile_DownloadCancelByName(assetFileName));
}
///
/// Gets the download status of an asset file by asset file ID.
///
/// The ID of the asset file to get the download status for.
///
/// An object containing the asset file ID, asset file name, and whether the asset file is downloaded.
///
public static Task StatusById(ulong assetId)
{
if (!CoreService.Initialized)
{
Debug.LogError(CoreService.NotInitializedError);
return null;
}
return new Task(CLIB.ppf_AssetFile_StatusById(assetId));
}
///
/// Gets the download status of an asset file by asset file name.
///
/// The name of the asset file to get the download status for.
///
/// An object containing the asset file ID, asset file name, and whether the asset file is downloaded.
///
public static Task StatusByName(string assetFileName)
{
if (!CoreService.Initialized)
{
Debug.LogError(CoreService.NotInitializedError);
return null;
}
return new Task(CLIB.ppf_AssetFile_StatusByName(assetFileName));
}
///
/// Gets the asset file list.
///
///
/// An asset file list. Each `AssetDetails` contains fields indicating
/// whether an asset file is purchased or downloaded.
///
public static Task GetList()
{
if (!CoreService.Initialized)
{
Debug.LogError(CoreService.NotInitializedError);
return null;
}
return new Task(CLIB.ppf_AssetFile_GetList());
}
///
/// Gets the next page of the asset file list.
///
/// The current page of the asset file list.
/// The next page of the asset file list.
public static Task GetNextAssetDetailsListPage(AssetDetailsList list)
{
if (!CoreService.Initialized)
{
Debug.LogError(CoreService.NotInitializedError);
return null;
}
if (!list.HasNextPage)
{
Debug.LogWarning("GetNextAssetDetailsListPage: List has no next page");
return null;
}
if (String.IsNullOrEmpty(list.NextPageParam))
{
Debug.LogWarning("GetNextAssetDetailsListPage: list.NextPageParam is empty");
return null;
}
return new Task(CLIB.ppf_AssetFile_GetNextAssetDetailsArrayPage(list.NextPageParam));
}
///
/// This notification is used to track the download progress of asset file.
/// The `Transferred` field indicates the number of bytes downloaded.
/// The `CompleteStatus` field indicates the download status.
///
/// The callback function.
public static void SetOnDownloadUpdateCallback(Message.Handler handler)
{
Looper.RegisterNotifyHandler(MessageType.Notification_AssetFile_DownloadUpdate, handler);
}
///
/// If the downloaded asset file is different from the original one,
/// the asset file will be automatically removed, and the app will receive a notification.
///
/// The callback function.
public static void SetOnDeleteForSafetyCallback(Message.Handler handler)
{
Looper.RegisterNotifyHandler(MessageType.Notification_AssetFile_DeleteForSafety, handler);
}
}
}