/// <summary> /// /// SUPPRIME UN PLAYER LOCAL PRECIS /// /// </summary> /// <param name="player"></param> private void RemovePlayerInLocalDataBase(LocalPlayerToSave player) { string filePath = Path.Combine(Application.persistentDataPath, fileNameDataBase); LocalPlayerToSaveList list; if (File.Exists(filePath)) { list = JsonUtility.FromJson <LocalPlayerToSaveList>(File.ReadAllText(filePath)); } else { list = new LocalPlayerToSaveList(); list.list = new System.Collections.Generic.List <LocalPlayerToSave>(); } for (int i = list.list.Count - 1; i >= 0; i--) { if (list.list[i].name == player.name) { list.list.Remove(list.list[i]); } } string ListJson = JsonUtility.ToJson(list); File.WriteAllText(filePath, ListJson); }
/// <summary> /// /// PERMET DE SAUVEGARDER LES DONNES LOCALES VERS LA SAUVEGARDE ONLINE /// /// </summary> private void TryToSaveOnline() { string filePath = Path.Combine(Application.persistentDataPath, fileNameDataBase); LocalPlayerToSaveList list; if (File.Exists(filePath)) { list = JsonUtility.FromJson <LocalPlayerToSaveList>(File.ReadAllText(filePath)); } else { list = new LocalPlayerToSaveList(); list.list = new System.Collections.Generic.List <LocalPlayerToSave>(); } foreach (LocalPlayerToSave player in list.list) { StartCoroutine(TryToSaveOnlineCoroutine(player)); } }
/// <summary> /// /// SAVE LOCALEMENT EN JSON /// /// </summary> /// <param name="level"></param> /// <param name="time"></param> /// <param name="score"></param> /// <param name="objects"></param> /// <param name="lives"></param> private void localSave(int level, float time, float score, int objects, int lives) { string filePath = Path.Combine(Application.persistentDataPath, fileNameDataBase); LocalPlayerToSaveList list; if (File.Exists(filePath)) { list = JsonUtility.FromJson <LocalPlayerToSaveList>(File.ReadAllText(filePath)); } else { list = new LocalPlayerToSaveList(); list.list = new System.Collections.Generic.List <LocalPlayerToSave>(); } list.list.Add(new LocalPlayerToSave(time, score, objects, lives, localCreds.username, localCreds.password, level)); string ListJson = JsonUtility.ToJson(list); File.WriteAllText(filePath, ListJson); }
/// <summary> /// /// RECUPERE LE TOP 5 DES JOUEURS SUR LA SAUVEGARDE LOCALE /// /// </summary> /// <param name="level"></param> private void LocalLeaderBoard(uint level) { string filePath = Path.Combine(Application.persistentDataPath, fileNameDataBase); LocalPlayerToSaveList list; if (File.Exists(filePath)) { list = JsonUtility.FromJson <LocalPlayerToSaveList>(File.ReadAllText(filePath)); } else { list = new LocalPlayerToSaveList(); list.list = new System.Collections.Generic.List <LocalPlayerToSave>(); } PlayerDatasList leaderboardList = new PlayerDatasList(); leaderboardList.list = new System.Collections.Generic.List <PlayerDatas>(); foreach (LocalPlayerToSave player in list.list) { if (player.level != level) { list.list.Remove(player); } } list.list.Sort((p1, p2) => p2.score.CompareTo(p1.score)); if (list.list.Count > 5) { list.list.RemoveRange(5, list.list.Count - 5); } foreach (LocalPlayerToSave player in list.list) { leaderboardList.list.Add(new PlayerDatas(player.score.ToString(), player.objects.ToString(), player.lives.ToString(), player.time.ToString(), player.name)); } SendLeaderBoard?.Invoke(leaderboardList); }