VersionUpdateUINotification.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using UnityEngine;
  2. using System.Collections;
  3. using TMPro;
  4. /// <summary>
  5. /// This component is responsible to capture the ClientUpdateAvailable notification and display it to the user.
  6. /// If the VersionInfo is flagged as forceUpdate, then the close button is removed, so the user can only click the Update button.
  7. ///
  8. /// This component should be placed on an active gameObject in the hierarchy. It will disable itself on Awake but will
  9. /// listen for the ClientUpdateAvailable notification.
  10. /// </summary>
  11. public class VersionUpdateUINotification : MonoBehaviour
  12. {
  13. public TextMeshProUGUI whatsNewLabel;
  14. public GameObject closeButton;
  15. void Awake()
  16. {
  17. CoreNotificationCenter.AddListener(OnClientUpdateAvailable, CoreNotificationType.ClientUpdateAvailable);
  18. gameObject.SetActive(false);
  19. }
  20. void OnDestroy()
  21. {
  22. CoreNotificationCenter.RemoveListener(OnClientUpdateAvailable, CoreNotificationType.ClientUpdateAvailable);
  23. }
  24. void OnClientUpdateAvailable(CoreNotification note)
  25. {
  26. VersionInfo versionInfo = (VersionInfo)note.data;
  27. Show(versionInfo.whatsNew, versionInfo.forceUpdate);
  28. }
  29. void Show(string whatsNew, bool forceUpdate)
  30. {
  31. GetComponent<ScreenBase>().Show();
  32. whatsNewLabel.text = whatsNew;
  33. if (forceUpdate)
  34. {
  35. closeButton.SetActive(false);
  36. }
  37. }
  38. public void OnUpdateClickMsg()
  39. {
  40. Application.OpenURL(GameConstants.APP_STORE_URL);
  41. }
  42. }