ChallengeResultsList.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using UnityEngine;
  2. using System.Collections;
  3. public class ChallengeResultsList : ListBase
  4. {
  5. public ChallengeResultItem challengeResultItemPrefab;
  6. protected override Transform CreateRandomItemForTestingInEditor(int index)
  7. {
  8. RequestInfo r = new RequestInfo();
  9. r.senderName = "Avatar "+index;
  10. ChallengeResultUIData data = new ChallengeResultUIData();
  11. data.otherScore = Random.Range(100, 500);
  12. data.playerScore = Random.Range(100, 500);
  13. ChallengeResultItem item = (ChallengeResultItem)Instantiate(challengeResultItemPrefab);
  14. item.SetData(data);
  15. return item.transform;
  16. }
  17. protected override bool HasItems()
  18. {
  19. ChallengeResult[] challengeResults = FacebookHelper.Instance.LoadedChallengeResults;
  20. return (challengeResults != null &&
  21. challengeResults.Length > 0);
  22. }
  23. protected override void CreateItems()
  24. {
  25. Logger.LogFlurryEvent("Challenge Results Opened");
  26. ChallengeResult[] challengeResults = FacebookHelper.Instance.LoadedChallengeResults;
  27. int row = 0;
  28. for(int i = 0; i < challengeResults.Length; i++)
  29. {
  30. ChallengeResult challengeResult = challengeResults[i];
  31. //skip any declined challenges
  32. if (challengeResult.WasChallengeDeclined())
  33. {
  34. continue;
  35. }
  36. ChallengeResultUIData data = new ChallengeResultUIData(challengeResult);
  37. ChallengeResultItem item = (ChallengeResultItem)Instantiate(challengeResultItemPrefab);
  38. item.SetData(data);
  39. Transform itemTransform = item.transform;
  40. PlaceItem(itemTransform, row++);
  41. }
  42. //save the ids in the player prefs, for future retrievals to be able to
  43. //detect new results
  44. string challengeIds = "";
  45. foreach (ChallengeResult result in challengeResults)
  46. {
  47. if (!result.WasChallengeDeclined())
  48. {
  49. challengeIds += result.challenge.id +",";
  50. }
  51. }
  52. PlayerPrefs.SetString(FacebookHelper.LAST_SEEN_CHALLENGE_IDS_KEY, challengeIds);
  53. PlayerPrefs.Save();
  54. //Since the player has seen them, post this notification, to trigger a reset of the counter
  55. NotificationCenter.Post(NotificationType.ReceivedNewChallengeResults, 0);
  56. }
  57. }