public void OnResult(Java.Lang.Object result)
            {
                var ar = result.JavaCast <IAchievementsLoadAchievementsResult>();

                if (ar != null)
                {
                    var count = ar.Achievements.Count;

                    AchievementInfo[] achievements = new AchievementInfo[count];

                    for (int idx = 0; idx < count; idx++)
                    {
                        var item = ar.Achievements.Get(idx);
                        var ach  = item.JavaCast <IAchievement>();


                        if (ach.Type == Android.Gms.Games.Achievement.Achievement.TypeIncremental)
                        {
                            achievements[idx] = new AchievementInfo(ach.AchievementId)
                            {
                                Completion = (ach.CurrentSteps * 100 / ach.TotalSteps)
                            };
                        }
                        else
                        {
                            achievements[idx] = new AchievementInfo(ach.AchievementId)
                            {
                                Completion = ach.State == Android.Gms.Games.Achievement.Achievement.StateUnlocked ? Achievement.Completed : 0
                            };
                        }
                    }

                    _achievementInfoDelegate(achievements);
                }
            }
Esempio n. 2
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);
                                }
                            });
                        }
                    }
                };
            }
        }