LivesRequestsCounter.cs 779 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using UnityEngine;
  2. using System.Collections;
  3. using TMPro;
  4. public class LivesRequestsCounter : MonoBehaviour
  5. {
  6. public TextMeshProUGUI notificationCount;
  7. void Awake()
  8. {
  9. MessageCenter.AddReceivedRequestsListener(OnReceivedRequests);
  10. FacebookHelper.AddLogoutListener(OnLogout);
  11. }
  12. void OnDestroy()
  13. {
  14. MessageCenter.RemoveReceivedRequestsListener(OnReceivedRequests);
  15. FacebookHelper.RemoveLogoutListener(OnLogout);
  16. }
  17. void OnReceivedRequests(ReceivedRequestsArgs requests)
  18. {
  19. int totalLifeRequests = requests.lifeDemandRequests.Count + requests.lifeRequests.Count;
  20. if (totalLifeRequests > 0)
  21. {
  22. notificationCount.text = totalLifeRequests.ToString();
  23. } else
  24. {
  25. notificationCount.text = "";
  26. }
  27. }
  28. void OnLogout()
  29. {
  30. notificationCount.text = "";
  31. }
  32. }