예제 #1
0
        public void Login()
        {
            GKLocalPlayer player = GKLocalPlayer.LocalPlayer;

            if (!player.Authenticated)
            {
                player.AuthenticateHandler = (UIViewController controller, NSError error) =>
                {
                    if (controller != null)
                    {
                        UIViewController parent = AppMain.Current.Services.GetService(typeof(UIViewController)) as UIViewController;
                        parent.PresentViewController(controller, true, null);
                    }
                    else
                    {
                        if (GKLocalPlayer.LocalPlayer.Authenticated)
                        {
                            _enabled = true;

                            GKLeaderboard.LoadLeaderboards((GKLeaderboard[] leaderboards, NSError error3) =>
                            {
                                if (leaderboards != null && leaderboards.Length > 0 && _leaderboardInfo != null)
                                {
                                    LeaderboardInfo[] info = new LeaderboardInfo[leaderboards.Length];

                                    for (int idx = 0; idx < leaderboards.Length; ++idx)
                                    {
                                        GKLeaderboard lb = leaderboards[idx];

                                        int score = 0;

                                        if (lb.LocalPlayerScore != null)
                                        {
                                            score = (int)lb.LocalPlayerScore.Value;
                                        }

                                        info[idx] = new LeaderboardInfo(lb.Identifier)
                                        {
                                            Score = score
                                        };
                                    }

                                    _leaderboardInfo(info);
                                }
                            });

                            GKAchievement.LoadAchievements((GKAchievement[] achievements, NSError error2) =>
                            {
                                if (achievements != null && achievements.Length > 0 && _achievementInfo != null)
                                {
                                    AchievementInfo[] info = new AchievementInfo[achievements.Length];

                                    for (int idx = 0; idx < achievements.Length; ++idx)
                                    {
                                        GKAchievement ach = achievements[idx];

                                        info[idx] = new AchievementInfo(ach.Identifier)
                                        {
                                            Completion = ach.Completed ? Achievement.Completed : (int)ach.PercentComplete
                                        };
                                    }

                                    _achievementInfo(info);
                                }
                            });
                        }
                    }
                };
            }
        }