/// <summary> /// Returns elements for constructing the leaderboard - based on team and /// </summary> /// <returns>The leaderboard elements.</returns> public override List <LeaderboardElement> GetLeaderboardElements() { List <LeaderboardElement> leaderboardElements = new List <LeaderboardElement>(); //Cache the color score dictionary from the gameManager - this is guaranteed to have the correct scores and actually is synced across the network Dictionary <Color, int> colorScoreDictionary = m_GameManager.colorScoreDictionary; //Cache the list length for efficiency int teamCount = m_Teams.Count; //Iterate through list of teams for (int i = 0; i < teamCount; ++i) { //Cache the team object as index i - this is because indexing is not a free action Team team = m_Teams[i]; int score = team.score; //check for score in the color score dictionary and use it if found if (colorScoreDictionary.ContainsKey(team.teamColor)) { score = colorScoreDictionary[team.teamColor]; } //Create the leaderboard element LeaderboardElement leaderboardElement = new LeaderboardElement(team.teamName, team.teamColor, score); //Add it to list leaderboardElements.Add(leaderboardElement); } //Ensure the leaderboard elements are sorted by score leaderboardElements.Sort(LeaderboardSort); return(leaderboardElements); }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ void Awake() { Application.targetFrameRate = 60; scrollView = GetComponentInChildren <exUIScrollView>(); clipping = GetComponentInChildren <exClipping>(); for (int i = 0; i < userInfos.Count; ++i) { GameObject el = Object.Instantiate(elementPrefab) as GameObject; LeaderboardElement leaderboardEL = el.GetComponent <LeaderboardElement>(); UserInfo userInfo = userInfos[i]; if (userInfo.icon != null) { leaderboardEL.Init(userInfo.icon, userInfo.name, userInfo.score); } else { leaderboardEL.Init(userInfo.iconURL, userInfo.name, userInfo.score); } AddElement(el); } }
private void OnGetUsersComplete(List <User> userList, GetUsersResult _result) { loadingWheel.SetActive(false); if (_result == GetUsersResult.Successfull) { RectTransform rt = Content.gameObject.GetComponent <RectTransform>(); rt.sizeDelta = new Vector2(0, userList.Count * 55); userList = userList.OrderByDescending(x => x.levelNumber).ToList(); tempElements = new LeaderboardElement[userList.Count]; foreach (User user in userList) { LeaderboardElement tempLeaderboardElement = Instantiate(leaderboardElement); tempLeaderboardElement.transform.SetParent(Content); tempLeaderboardElement.transform.LeanScale(new Vector3(1, 1, 1), 0f); tempElements[userList.IndexOf(user)] = tempLeaderboardElement; tempLeaderboardElement.LeaderboardElementSetup((userList.IndexOf(user) + 1), user.username, user.levelNumber); } } else { DisplayErrorMessage("Error, try again"); } }
private void Singleton_OnLeaderReceived(object data) { foreach (Dictionary <string, object> item in data as List <object> ) { GameObject subj = Instantiate(subjInfoPrefab) as GameObject; LeaderboardElement le = subj.GetComponent <LeaderboardElement>(); le.SetData(item["SubjName"].ToString(), int.Parse(item["Score"].ToString())); subj.transform.SetParent(elementsPanel.transform); subj.transform.localScale = Vector3.one; } }
/// <summary> /// Returns elements for constructing the leaderboard /// </summary> /// <returns>The leaderboard elements.</returns> public virtual List <LeaderboardElement> GetLeaderboardElements() { List <LeaderboardElement> leaderboardElements = new List <LeaderboardElement>(); List <TankManager> matchTanks = GameManager.s_Tanks; int tankCount = matchTanks.Count; for (int i = 0; i < tankCount; ++i) { TankManager currentTank = matchTanks[i]; LeaderboardElement leaderboardElement = new LeaderboardElement(currentTank.playerName, currentTank.playerColor, currentTank.score); leaderboardElements.Add(leaderboardElement); } leaderboardElements.Sort(LeaderboardSort); return(leaderboardElements); }
public void LoadLeaderboard() { //Results = new List<FBresult>() { FAKE RESULTS // new FBresult(Resources.Load<Texture>("Profile1"), 1), // new FBresult(Resources.Load<Texture>("Profile2"), 2), // new FBresult(Resources.Load<Texture>("Profile3"), 3), // new FBresult(Resources.Load<Texture>("Profile4"), 4), // new FBresult(Resources.Load<Texture>("Profile5"), 5), // new FBresult(Resources.Load<Texture>("Profile6"), 6), // new FBresult(Resources.Load<Texture>("Profile7"), 7), // new FBresult(Resources.Load<Texture>("Profile8"), 8) //}; List <FBresult> Results = null; if (FB.IsLoggedIn) { FBGraph.GetFriends(); FBGraph.GetScores(() => { Results = new List <FBresult>(); for (int i = 0; i < Game.Scores.Count; i++) { var entry = (Dictionary <string, object>)Game.Scores[i]; var user = (Dictionary <string, object>)entry["user"]; //((string) user["name"]).Split(new char[]{' '})[0] Texture picture; if (Game.FriendImages.TryGetValue((string)user["id"], out picture)) { Results.Add(new FBresult(GraphUtil.GetScoreFromEntry(entry), picture)); } else { Results.Add(new FBresult(GraphUtil.GetScoreFromEntry(entry), (string)user["id"])); } } Results = Results.OrderByDescending(c => c.score).ToList(); for (int i = 0; i < Results.Count; i++) { var e = Instantiate(LeaderboardElement); e.transform.SetParent(LeaderboardElementGroup.transform, false); LeaderboardElement refer = e.GetComponent <LeaderboardElement>(); LeaderboardElementGroup.SetActive(true); if (Results[i].image == null) { refer.initalise(Results[i].score, Results[i].id); } else { refer.initalise(Results[i].score, Results[i].image); } refer.Displacer.position = new Vector3(-1000, 0, 0); LeanTween.value(refer.Displacer.gameObject, refer.Displacer.localPosition.x, 0f, 1f).setEaseInOutCubic().setDelay(0.1f * (Results.Count - i)).setOnUpdate((f) => { refer.Displacer.localPosition = new Vector3(f, 0, 0); }); } LeaderboardStopLoading(); }); } else { LeaderboardStopLoading(); LeaderboardElementGroup.SetActive(true); var e = Instantiate(Resources.Load <GameObject>("LoginPleaseFacebook")); e.transform.SetParent(LeaderboardElementGroup.transform, false); var dif = e.transform.GetChild(0); AnimatableLeader.Add(dif.GetComponent <Text>()); dif.transform.position = new Vector3(-1100, 0, 0); LeanTween.value(dif.gameObject, dif.localPosition.x, 0f, 1f).setEaseInOutCubic().setOnUpdate((f) => { dif.localPosition = new Vector3(f, 0, 0); }); } }
/// <summary> /// Used for sorting the leaderboard /// </summary> /// <returns>The sort.</returns> /// <param name="player1">Player1.</param> /// <param name="player2">Player2.</param> protected int LeaderboardSort(LeaderboardElement player1, LeaderboardElement player2) { return(player2.score - player1.score); }