ChallengeRequestsCounter.cs 732 B

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