在store建立对应的排行榜数据后使用
public partial class XboxLiveHelper { public static void WriteLeardBoard(string name, int statValue) { if (!is_online) return; StatisticManager statManager = StatisticManager.SingletonInstance; double previous = 0; try { previous = statManager.GetStatistic(xboxUser, name).AsNumber; } catch (Exception ex) { Debug.WriteLine(ex.Message); } previous += statValue; statManager.SetStatisticIntegerData(xboxUser, name, (int)previous); statManager.RequestFlushToService(xboxUser); statManager.DoWork(); } public static async Task<LeaderboardResult> GetLeaderboardAsync(string leaderBoardName) { if (!is_online) return null; var statManager = StatisticManager.SingletonInstance; LeaderboardQuery query = new LeaderboardQuery { SkipResultToMe = true, //SkipResultToRank = 100, MaxItems = 1, }; statManager.GetLeaderboard(xboxUser, leaderBoardName, query); int finished = 0; do { Debug.Write(". "); await Task.Delay(100); finished += 100; foreach (StatisticEvent statEvent in statManager.DoWork()) { if (statEvent.EventType == StatisticEventType.GetLeaderboardComplete && statEvent.ErrorCode == 0) { LeaderboardResultEventArgs leaderArgs = (LeaderboardResultEventArgs)statEvent.EventArgs; LeaderboardResult leaderboardResult = leaderArgs.Result; return leaderboardResult; } } } while (finished <= 3000); return null; } public static async Task<LeaderboardResult> GetLeaderboardAsync(string leaderBoardName, uint max_items) { if (!is_online) return null; var statManager = StatisticManager.SingletonInstance; LeaderboardQuery query = new LeaderboardQuery { SkipResultToMe = true, //SkipResultToRank = 100, MaxItems = max_items, }; statManager.GetLeaderboard(xboxUser, leaderBoardName, query); int finished = 0; do { Debug.Write(". "); await Task.Delay(100); finished += 100; foreach (StatisticEvent statEvent in statManager.DoWork()) { if (statEvent.EventType == StatisticEventType.GetLeaderboardComplete && statEvent.ErrorCode == 0) { LeaderboardResultEventArgs leaderArgs = (LeaderboardResultEventArgs)statEvent.EventArgs; LeaderboardResult leaderboardResult = leaderArgs.Result; return leaderboardResult; } } } while (finished <= 3000); return null; } }
end