using System; using System.Collections.Generic; using UnityEngine; namespace TowerDevil { [Serializable] internal sealed class RankEntry { public int rank; public string name; public long score; public bool mine; } [Serializable] internal sealed class RankResult { public string error; public RankEntry[] entries; } internal static class GameCenterRanks { #if UNITY_IOS && !UNITY_EDITOR static Profile activeProfile; public static void Sync(Profile profile) { activeProfile = profile; var standing = profile.CurrentStanding; GameCenterNative.Sync(standing?.playerID, standing?.bestNight ?? 0, standing?.totalScore ?? 0, SignedIn); } static void SignedIn(string playerID) { if (activeProfile.CurrentStanding?.playerID == playerID) { Sync(activeProfile); return; } activeProfile.SelectGameCenterPlayer(playerID); activeProfile.Save(); } public static void Load(bool byScore, Profile profile, Action completed) { GameCenterNative.Load(byScore ? 1 : 0, json => completed?.Invoke(JsonUtility.FromJson(json))); } #else public static void Sync(Profile profile) { } public static void Load(bool byScore, Profile profile, Action completed) { string[] names = { "GrimWarden", "AshVex", "MolochJr", "SableHorn", "Pyre", "Nyx", "BoneTail", "Emberly", "DuskWing", "Ruin" }; int[] values = byScore ? new[] { 31240, 26880, 24110, 20930, 17420, 14880, 12060, 9840, 7620, 4980 } : new[] { 48, 43, 39, 34, 29, 25, 21, 17, 14, 9 }; var rows = new List(); for (int i = 0; i < names.Length; i++) rows.Add(new RankEntry { name = names[i], score = values[i] }); rows.Add(new RankEntry { name = profile.name, score = byScore ? profile.score : profile.bestNight, mine = true }); rows.Sort((a, b) => b.score.CompareTo(a.score)); for (int i = 0; i < rows.Count; i++) rows[i].rank = i + 1; completed(new RankResult { entries = rows.ToArray() }); } #endif } }