void SendDataToBoard(UltimatePinballLeaderboardData Data, int Player) { if ((!HasDataSentP1) && (Player == 0)) { if (Player1_LB_Data.PlayerName == "") { Player1_LB_Data.PlayerName = "Unknown"; } else { Player1_LB_Data.PlayerName = Player1_LB_Data.PlayerName.Substring(0, 1).ToString() + Player1_LB_Data.PlayerName.Substring(1).ToString().ToLower(); Player1Name.text = "Player 1 - " + Player1_LB_Data.PlayerName; } StartCoroutine(OnlineLeaderboardManager.Send_UltimatePinball_Data_Online(Data)); HasDataSentP1 = true; Debug.Log("Data Send P1"); } else if ((!HasDataSentP2) && (Player == 1)) { if (Player2_LB_Data.PlayerName == "") { Player2_LB_Data.PlayerName = "Unknown"; } else { Player2_LB_Data.PlayerName = Player2_LB_Data.PlayerName.Substring(0, 1).ToString() + Player2_LB_Data.PlayerName.Substring(1).ToString().ToLower(); Player2Name.text = "Player 2 - " + Player2_LB_Data.PlayerName; } StartCoroutine(OnlineLeaderboardManager.Send_UltimatePinball_Data_Online(Data)); HasDataSentP2 = true; Debug.Log("Data Send P2"); } }
IEnumerator Call_Ultimate_Pinball_Data_Online_Timer() { List <UltimatePinballLeaderboardData> ListData = new List <UltimatePinballLeaderboardData>(10); List <string> ReceivedPlayerName = new List <string>(); List <string> ReceivedPlayerScore = new List <string>(); List <string> ReceivedPlayerPlatform = new List <string>(); List <string> ReceivedPlayerGamemode = new List <string>(); UnityWebRequest Request = UnityWebRequest.Get(SaveManager.LoadOnlineBoardPath().onlineLeaderboardsBasePath + "getpinballtimertop.php?"); yield return(Request.SendWebRequest()); if (Request.error == null) { string[] Values = Request.downloadHandler.text.Split("\r"[0]); // only get the top 5 entries for (int i = 0; i < Values.Length; i++) { if (i % 4 == 0) { ReceivedPlayerName.Add(Values[i]); } else if (i % 4 == 1) { ReceivedPlayerScore.Add(Values[i]); } else if (i % 4 == 2) { ReceivedPlayerPlatform.Add(Values[i]); } else if (i % 4 == 3) { ReceivedPlayerGamemode.Add(Values[i]); } else { Debug.LogError("Value to added to any list!"); } } for (int i = 0; i < ReceivedPlayerPlatform.Count; i++) { UltimatePinballLeaderboardData Data = new UltimatePinballLeaderboardData(); Data.PlayerName = ReceivedPlayerName[i]; Data.PlayerScore = int.Parse(ReceivedPlayerScore[i]); Data.PlayerPlatform = ReceivedPlayerPlatform[i]; Data.PlayerGamemode = int.Parse(ReceivedPlayerGamemode[i]); ListData.Add(Data); } ZeData = ListData; } }
/// ========================================================================================================================= /// ========================================================================================================================= /// /// Ultimate Pinball ( Saving / Loading ) /// /// ========================================================================================================================= /// ========================================================================================================================= /// <summary> /// Saves a new entry into the local leaderboard file for ultimate pinball... /// Uses APPEND to add entry /// </summary> /// <param name="_data">data to be added</param> public static void SaveUltimatePinballToLocal(UltimatePinballLeaderboardData _data) { BinaryFormatter Formatter = new BinaryFormatter(); string SavePath = Application.persistentDataPath + "/ultimatepinball.malf"; FileStream Stream; if (File.Exists(SavePath)) { Stream = new FileStream(SavePath, FileMode.Append); } else { Stream = new FileStream(SavePath, FileMode.Create); } Formatter.Serialize(Stream, _data); Stream.Close(); }