VersionUpdateUINotification.cs 1.3 KB

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