/// <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> /// /// ENVOIE UNE REQUETE AU SERVEUR POUR SAUVEGARDER UN PLAYER LOCAL /// DEMANDE LA SUPPRESSION DU PLAYER LOCAL /// /// </summary> /// <param name="player"></param> /// <returns></returns> private IEnumerator TryToSaveOnlineCoroutine(LocalPlayerToSave player) { string json = JsonUtility.ToJson(player); string url = "https://comisartdigitalsophia.herokuapp.com/level/localToOnline"; using (UnityWebRequest req = PostJson(url, json)) { yield return(req.SendWebRequest()); if (req.isNetworkError || req.isHttpError) { IsInLocal = true; } else { RemovePlayerInLocalDataBase(player); IsInLocal = false; } } }