1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using UnityEngine;
- using System.Collections;
- public class ChallengeResultsList : ListBase
- {
- public ChallengeResultItem challengeResultItemPrefab;
- protected override Transform CreateRandomItemForTestingInEditor(int index)
- {
- RequestInfo r = new RequestInfo();
- r.senderName = "Avatar "+index;
- ChallengeResultUIData data = new ChallengeResultUIData();
- data.otherScore = Random.Range(100, 500);
- data.playerScore = Random.Range(100, 500);
- ChallengeResultItem item = (ChallengeResultItem)Instantiate(challengeResultItemPrefab);
- item.SetData(data);
- return item.transform;
- }
- protected override bool HasItems()
- {
- ChallengeResult[] challengeResults = FacebookHelper.Instance.LoadedChallengeResults;
- return (challengeResults != null &&
- challengeResults.Length > 0);
- }
- protected override void CreateItems()
- {
- Logger.LogFlurryEvent("Challenge Results Opened");
- ChallengeResult[] challengeResults = FacebookHelper.Instance.LoadedChallengeResults;
- int row = 0;
- for(int i = 0; i < challengeResults.Length; i++)
- {
- ChallengeResult challengeResult = challengeResults[i];
- //skip any declined challenges
- if (challengeResult.WasChallengeDeclined())
- {
- continue;
- }
- ChallengeResultUIData data = new ChallengeResultUIData(challengeResult);
- ChallengeResultItem item = (ChallengeResultItem)Instantiate(challengeResultItemPrefab);
- item.SetData(data);
- Transform itemTransform = item.transform;
- PlaceItem(itemTransform, row++);
- }
- //save the ids in the player prefs, for future retrievals to be able to
- //detect new results
- string challengeIds = "";
- foreach (ChallengeResult result in challengeResults)
- {
- if (!result.WasChallengeDeclined())
- {
- challengeIds += result.challenge.id +",";
- }
- }
- PlayerPrefs.SetString(FacebookHelper.LAST_SEEN_CHALLENGE_IDS_KEY, challengeIds);
- PlayerPrefs.Save();
- //Since the player has seen them, post this notification, to trigger a reset of the counter
- NotificationCenter.Post(NotificationType.ReceivedNewChallengeResults, 0);
- }
- }
|