using Appcharge.Updater;
using Appcharge.Updater.Interfaces;
using Appcharge.Updater.Models;
using UnityEngine;
using UnityEngine.UI;
public class Sample : MonoBehaviour, IUpdateCallback
{
[SerializeField] private Text _logger;
[SerializeField] private Button _btnCheckForUpdate;
[SerializeField] private Button _btnInstallUpdate;
private UpdateStatusModel _status;
private void Start()
{
UpdateController.Instance.Init("sandbox", "checkoutPublicKey", "customerId", this);
}
#region Interface Callback Methods
public void OnInitializationSuccess()
{
_logger.text = "Initialization successful.";
_btnCheckForUpdate.gameObject.SetActive(true);
}
public void OnUpdateStatus(UpdateStatusModel status)
{
_status = status;
_logger.text = $"A new version of your app is available: {status.Message}";
_btnInstallUpdate.gameObject.SetActive(true);
}
public void OnDownloadStarted()
{
_logger.text = "Downloading the new app version.";
}
public void OnProgress(int progress)
{
_logger.text = $"Progress: {progress}%";
}
public void OnDownloadEnded()
{
_logger.text = "The new app version has been downloaded.";
}
public void OnInstallationReady()
{
_logger.text = "The new app version has been downloaded and is ready to install.";
}
public void OnError(int errorCode)
{
_logger.text = $"Error: {errorCode}";
}
#endregion
public void CheckForUpdates()
{
UpdateController.Instance.CheckForUpdates();
}
public void InstallUpdate()
{
if (_status == null)
{
_logger.text = "No status";
return;
}
if (_status.IsUpdateAvailable)
{
UpdateController.Instance.InstallUpdate();
}
}
}