using UnityEngine;
using System.Collections;
using TMPro;
///
/// This component is responsible to capture the ClientUpdateAvailable notification and display it to the user.
/// If the VersionInfo is flagged as forceUpdate, then the close button is removed, so the user can only click the Update button.
///
/// This component should be placed on an active gameObject in the hierarchy. It will disable itself on Awake but will
/// listen for the ClientUpdateAvailable notification.
///
public class VersionUpdateUINotification : MonoBehaviour
{
public TextMeshProUGUI whatsNewLabel;
public GameObject closeButton;
void Awake()
{
CoreNotificationCenter.AddListener(OnClientUpdateAvailable, CoreNotificationType.ClientUpdateAvailable);
gameObject.SetActive(false);
}
void OnDestroy()
{
CoreNotificationCenter.RemoveListener(OnClientUpdateAvailable, CoreNotificationType.ClientUpdateAvailable);
}
void OnClientUpdateAvailable(CoreNotification note)
{
VersionInfo versionInfo = (VersionInfo)note.data;
Show(versionInfo.whatsNew, versionInfo.forceUpdate);
}
void Show(string whatsNew, bool forceUpdate)
{
GetComponent().Show();
whatsNewLabel.text = whatsNew;
if (forceUpdate)
{
closeButton.SetActive(false);
}
}
public void OnUpdateClickMsg()
{
Application.OpenURL(GameConstants.APP_STORE_URL);
}
}