void OnGUI() { GUI.Label(new Rect(10, 20, 400, 40), "Friend List Load Example", headerStyle); if (GUI.Button(new Rect(300, 10, 150, 50), "Load Friends")) { GameCenterManager.OnFriendsListLoaded += OnFriendsListLoaded; GameCenterManager.RetrieveFriends(); } if (GUI.Button(new Rect(500, 10, 150, 50), "Invite Friends")) { GK_FriendRequest r = new GK_FriendRequest(); r.Send(); } if (GUI.Button(new Rect(700, 10, 150, 50), "Invite with Emails")) { GK_FriendRequest r = new GK_FriendRequest(); r.addRecipientsWithEmailAddresses("*****@*****.**", "*****@*****.**"); r.Send(); } if (!renderFriendsList) { return; } if (GUI.Button(new Rect(500, 10, 180, 50), "Leaberboard Challenge All")) { GameCenterManager.IssueLeaderboardChallenge(ChallengeLeaderboard, "Your message here", GameCenterManager.FriendsList.ToArray()); } if (GUI.Button(new Rect(730, 10, 180, 50), "Achievement Challenge All")) { GameCenterManager.IssueAchievementChallenge(ChallengeAchievement, "Your message here", GameCenterManager.FriendsList.ToArray()); } GUI.Label(new Rect(10, 90, 100, 40), "id", boardStyle); GUI.Label(new Rect(150, 90, 100, 40), "name", boardStyle);; GUI.Label(new Rect(300, 90, 100, 40), "avatar ", boardStyle); int i = 1; foreach (string FriendId in GameCenterManager.FriendsList) { GK_Player player = GameCenterManager.GetPlayerById(FriendId); if (player != null) { GUI.Label(new Rect(10, 90 + 70 * i, 100, 40), player.Id, boardStyle); GUI.Label(new Rect(150, 90 + 70 * i, 100, 40), player.Alias, boardStyle); if (player.SmallPhoto != null) { GUI.DrawTexture(new Rect(300, 75 + 70 * i, 50, 50), player.SmallPhoto); } else { GUI.Label(new Rect(300, 90 + 70 * i, 100, 40), "no photo ", boardStyle); } if (GUI.Button(new Rect(450, 90 + 70 * i, 150, 30), "Challenge Leaderboard")) { GameCenterManager.IssueLeaderboardChallenge(ChallengeLeaderboard, "Your message here", FriendId); } if (GUI.Button(new Rect(650, 90 + 70 * i, 150, 30), "Challenge Achievement")) { GameCenterManager.IssueAchievementChallenge(ChallengeAchievement, "Your message here", FriendId); } i++; } } }
void OnGUI() { GUI.Label(new Rect(10, 20, 400, 40), "Friend List Load Example", headerStyle); if (GUI.Button(new Rect(300, 10, 150, 50), "Load Friends")) { GameCenterManager.OnFriendsListLoaded += OnFriendsListLoaded; GameCenterManager.RetrieveFriends(); } if (!renderFriendsList) { return; } if (GUI.Button(new Rect(500, 10, 180, 50), "Leaberboard Challenge All")) { GameCenterManager.IssueLeaderboardChallenge(ChallengeLeaderboard, "Your message here", GameCenterManager.FriendsList.ToArray()); } if (GUI.Button(new Rect(730, 10, 180, 50), "Achievement Challenge All")) { GameCenterManager.IssueAchievementChallenge(ChallengeAchievement, "Your message here", GameCenterManager.FriendsList.ToArray()); } GUI.Label(new Rect(10, 90, 100, 40), "id", boardStyle); GUI.Label(new Rect(150, 90, 100, 40), "name", boardStyle);; GUI.Label(new Rect(300, 90, 100, 40), "avatar ", boardStyle); int i = 1; foreach (string FriendId in GameCenterManager.FriendsList) { GameCenterPlayerTemplate player = GameCenterManager.GetPlayerById(FriendId); if (player != null) { GUI.Label(new Rect(10, 90 + 70 * i, 100, 40), player.PlayerId, boardStyle); GUI.Label(new Rect(150, 90 + 70 * i, 100, 40), player.Alias, boardStyle); if (player.Avatar != null) { GUI.DrawTexture(new Rect(300, 75 + 70 * i, 50, 50), player.Avatar); } else { GUI.Label(new Rect(300, 90 + 70 * i, 100, 40), "no photo ", boardStyle); } if (GUI.Button(new Rect(450, 90 + 70 * i, 150, 30), "Challenge Leaderboard")) { GameCenterManager.IssueLeaderboardChallenge(ChallengeLeaderboard, "Your message here", FriendId); } if (GUI.Button(new Rect(650, 90 + 70 * i, 150, 30), "Challenge Achievement")) { GameCenterManager.IssueAchievementChallenge(ChallengeAchievement, "Your message here", FriendId); } i++; } } }
void OnGUI() { GUI.Label(new Rect(10, 20, 400, 40), "Custom Leaderboard GUI Example", headerStyle); if (GUI.Button(new Rect(400, 10, 150, 50), "Load Friends Scores")) { GameCenterManager.LoadScore(leaderboardId, 1, 10, GK_TimeSpan.ALL_TIME, GK_CollectionType.FRIENDS); } if (GUI.Button(new Rect(600, 10, 150, 50), "Load Global Scores")) { GameCenterManager.LoadScore(leaderboardId, 50, 150, GK_TimeSpan.ALL_TIME, GK_CollectionType.GLOBAL); } Color defaultColor = GUI.color; if (displayCollection == GK_CollectionType.GLOBAL) { GUI.color = Color.green; } if (GUI.Button(new Rect(800, 10, 170, 50), "Displaying Global Scores")) { displayCollection = GK_CollectionType.GLOBAL; } GUI.color = defaultColor; if (displayCollection == GK_CollectionType.FRIENDS) { GUI.color = Color.green; } if (GUI.Button(new Rect(800, 70, 170, 50), "Displaying Friends Scores")) { displayCollection = GK_CollectionType.FRIENDS; } GUI.color = defaultColor; GUI.Label(new Rect(10, 90, 100, 40), "rank", boardStyle); GUI.Label(new Rect(100, 90, 100, 40), "score", boardStyle); GUI.Label(new Rect(200, 90, 100, 40), "playerId", boardStyle); GUI.Label(new Rect(400, 90, 100, 40), "name ", boardStyle); GUI.Label(new Rect(550, 90, 100, 40), "avatar ", boardStyle); if (loadedLeaderboard != null) { for (int i = 1; i < 10; i++) { GK_Score score = loadedLeaderboard.GetScore(i, GK_TimeSpan.ALL_TIME, displayCollection); if (score != null) { GUI.Label(new Rect(10, 90 + 70 * i, 100, 40), i.ToString(), boardStyle); GUI.Label(new Rect(100, 90 + 70 * i, 100, 40), score.GetLongScore().ToString(), boardStyle); GUI.Label(new Rect(200, 90 + 70 * i, 100, 40), score.playerId, boardStyle); GK_Player player = GameCenterManager.GetPlayerById(score.playerId); if (player != null) { GUI.Label(new Rect(400, 90 + 70 * i, 100, 40), player.Alias, boardStyle); if (player.SmallPhoto != null) { GUI.DrawTexture(new Rect(550, 75 + 70 * i, 50, 50), player.SmallPhoto); } else { GUI.Label(new Rect(550, 90 + 70 * i, 100, 40), "no photo ", boardStyle); } } if (GUI.Button(new Rect(650, 90 + 70 * i, 100, 30), "Challenge")) { GameCenterManager.IssueLeaderboardChallenge(leaderboardId, "Your message here", score.playerId); } } } } }
//-------------------------------------- // PUBLIC METHODS //-------------------------------------- void OnGUI() { UpdateToStartPos(); if (GameCenterManager.Player != null) { GUI.Label(new Rect(100, 10, Screen.width, 40), "ID: " + GameCenterManager.Player.Id); GUI.Label(new Rect(100, 20, Screen.width, 40), "Name: " + GameCenterManager.Player.DisplayName); GUI.Label(new Rect(100, 30, Screen.width, 40), "Alias: " + GameCenterManager.Player.Alias); //avatar loading will take a while after the user is connectd //so we will draw it only after instantiation to avoid null pointer check //if you whant to know exaxtly when the avatar is loaded, you can subscribe on //GameCenterManager.OnUserInfoLoaded action //and checl for a spesific user ID if (GameCenterManager.Player.SmallPhoto != null) { GUI.DrawTexture(new Rect(10, 10, 75, 75), GameCenterManager.Player.SmallPhoto); } } StartY += YLableStep; StartY += YLableStep; StartY += YLableStep; GUI.Label(new Rect(StartX, StartY, Screen.width, 40), "Game Center Leaderboards", style); StartY += YLableStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Show Leaderboards")) { GameCenterManager.ShowLeaderboards(); } StartX += XButtonStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Load Sets Info")) { GameCenterManager.OnLeaderboardSetsInfoLoaded += OnLeaderboardSetsInfoLoaded; GameCenterManager.LoadLeaderboardSetInfo(); } StartX = XStartPos; StartY += YButtonStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Show Leaderboard 1")) { GameCenterManager.ShowLeaderboard(leaderBoardId_1); } StartX += XButtonStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Report Score LB 1")) { hiScore++; GameCenterManager.ReportScore(hiScore, leaderBoardId_1); } StartX += XButtonStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Get Score LB 1")) { GameCenterManager.LoadLeaderboardInfo(leaderBoardId_1); } StartX = XStartPos; StartY += YButtonStep; StartY += YLableStep; GUI.Label(new Rect(StartX, StartY, Screen.width, 40), "Leaderboard #2, user best score: " + LB2BestScores.ToString(), style); StartY += YLableStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Show Leader Board2")) { GameCenterManager.ShowLeaderboard(leaderBoardId_2); } StartX += XButtonStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Show Leaderboard 2 Today")) { GameCenterManager.ShowLeaderboard(leaderBoardId_2, GK_TimeSpan.TODAY); } StartX += XButtonStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Report Score LB2")) { hiScore++; GameCenterManager.OnScoreSubmitted += OnScoreSubmitted; GameCenterManager.ReportScore(hiScore, leaderBoardId_2); } StartX += XButtonStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Get Score LB 2")) { GameCenterManager.LoadLeaderboardInfo(leaderBoardId_2); } StartX += XButtonStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Send Challenge")) { GameCenterManager.IssueLeaderboardChallenge(leaderBoardId_2, "Here's a tiny challenge for you"); } StartX = XStartPos; StartY += YButtonStep; StartY += YLableStep; GUI.Label(new Rect(StartX, StartY, Screen.width, 40), "Game Center Achievements", style); StartY += YLableStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Show Achievements")) { GameCenterManager.ShowAchievements(); } StartX += XButtonStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Reset Achievements")) { GameCenterManager.ResetAchievements(); } StartX += XButtonStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Submit Achievements1")) { GameCenterManager.SubmitAchievement(GameCenterManager.GetAchievementProgress(TEST_ACHIEVEMENT_1_ID) + 2.432f, TEST_ACHIEVEMENT_1_ID); } StartX += XButtonStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Submit Achievements2")) { GameCenterManager.SubmitAchievement(88.66f, TEST_ACHIEVEMENT_2_ID, false); } StartX += XButtonStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Send Challenge")) { GameCenterManager.IssueAchievementChallenge(TEST_ACHIEVEMENT_1_ID, "Here's a tiny challenge for you"); } StartX = XStartPos; StartY += YButtonStep; StartY += YLableStep; GUI.Label(new Rect(StartX, StartY, Screen.width, 40), "More", style); StartY += YLableStep; if (GUI.Button(new Rect(StartX, StartY, buttonWidth, buttonHeight), "Retrieve Signature")) { GameCenterManager.RetrievePlayerSignature(); GameCenterManager.OnPlayerSignatureRetrieveResult += OnPlayerSignatureRetrieveResult; } }