//void OnGUI() //{ // // TODO: Figure out why this doesn't work when runnning a standalone game build outside of the editor // Event e = Event.current; // // Only check one key release (i.e. EventType.KeyUp) instead of key press to prevent this from executing multiple times // if (e.type == EventType.KeyUp) // { // Debug.Log("Some key pressed."); // if (e.shift && e.control) // { // Debug.Log("CTRL + SHIFT hotkey pressed."); // if (e.keyCode == KeyCode.R) // { // // CTRL + SHIFT + R // Debug.Log("CTRL + SHIFT + R hotkey pressed."); // Debug.Log("R hotkey pressed."); // SaveAndResetGame(); // } // } // else if (e.keyCode == KeyCode.LeftArrow || e.keyCode == KeyCode.RightArrow) // { // Debug.Log("LeftArrow or RightArrow hotkey pressed."); // // CTRL + SHIFT + LeftArrow or CTRL + SHIFT + RightArrow // // This is just a placeholder hotkey used test specific functions on command // string next_score_location = "left"; // if (e.keyCode == KeyCode.LeftArrow) // { // // Debug.Log("CTRL + SHIFT + LeftArrow hotkey pressed."); // Debug.Log("LeftArrow hotkey pressed."); // } // else if (e.keyCode == KeyCode.RightArrow) // { // // Debug.Log("CTRL + SHIFT + RighttArrow hotkey pressed."); // Debug.Log("RighttArrow hotkey pressed."); // next_score_location = "right"; // } // // Debug.Log("CTRL + SHIFT + L hotkey pressed."); // // Debug.Log("L hotkey pressed. Reset the scene to the state of the last saved score."); // if (this.saved_score_entry_list.Count > 0) // { // this.LoadScore(next_score_location: next_score_location); // } // else // { // Debug.Log("Warning: You're attempting to load a saved score when one is not available. Try saving first with Control+Shift+R..."); // } // } // } //} public void LoadSavedScores(List <string> scores_to_load = null) { Debug.Log("LoadSavedScores() called"); List <string> file_contents_list = scores_to_load; if (file_contents_list == null) { // Calling LoadSavedScores() all the time seems kinda wasteful, since most of the work is already done on Start() // TODO: Only load the save file if no saved/serialized scores have been provided to this method this.saved_score_entry_list = new List <PlayerScoreEntry>(); string file_contents_string = this.save_file_handler.Read(); file_contents_list = this.save_file_handler.ParseFileContents(file_contents_string: file_contents_string); } foreach (string saved_score_entry_json in file_contents_list) { if (saved_score_entry_json != "") { PlayerScoreEntry loaded_score_entry = JsonConvert.DeserializeObject <PlayerScoreEntry>(saved_score_entry_json); this.saved_score_entry_list.Add(loaded_score_entry); } } // Default the score entry index to the size of the list for use in previous/next score navigation // The LoadScore() logic will adjust the index appropriately to prevent index out of bounds errors this.current_score_entry_index = this.saved_score_entry_list.Count; }
public void UpdateScoreTable() { PlayerScoreEntry[] playerScoreEntries = listContent.GetComponentsInChildren <PlayerScoreEntry>(); //supprimmer le contenu de la liste if (playerScoreEntries != null) { foreach (var entry in playerScoreEntries) { Destroy(entry.gameObject); } } //ajouter les joueurs à la liste foreach (Player player in PhotonNetwork.PlayerList) { GameObject entry = Instantiate(playerEntryPrefab, listContent.transform); PlayerScoreEntry entryDetails = entry.GetComponent <PlayerScoreEntry>(); if (entryDetails != null) { entryDetails.player = player; entryDetails.SetPlayerName(player.NickName); entryDetails.UpdateFromProperties(player); } object ping; if (player.CustomProperties.TryGetValue(SlideRaceGame.PLAYER_PING, out ping)) { entryDetails.SetPing((int)ping); } } }
public void SaveScore() { Debug.Log("Now saving score..."); DateTime timestamp = System.DateTime.UtcNow; this.InitToggleStateDictionary(force_reset: true); this.UpdateToggleStateDictionary(); PlayerScoreEntry current_score_entry = new PlayerScoreEntry(new_player: this.current_player, new_timestamp: timestamp, new_score_total: this.points_earned, new_score_summary: this.score_summary_json); this.saved_score_entry_list.Add(current_score_entry); this.current_score_entry = current_score_entry; this.current_score_entry_index = this.saved_score_entry_list.Count - 1; // TODO: Implement the following score serialization logic in a SerializeScore() method this.serialized_score_entry = JsonConvert.SerializeObject(current_score_entry); // TODO: Update DeserializeScore() method to support ScoreEntry instances // this.current_score_entry = JsonConvert.DeserializeObject<ScoreEntry>(this.serialized_score_entry); this.save_file_handler.WriteString(this.serialized_score_entry); // The score has been saved to the score save file // Load the saved score to update the saved_score_entry_list List <string> newly_save_scores = new List <string>(); newly_save_scores.Add(this.serialized_score_entry); LoadSavedScores(scores_to_load: newly_save_scores); }
public void LoadScore(Dictionary <string, List <string> > loaded_score_summary = null, int loaded_score_summary_index = 0, string next_score_location = null) { // Reloads the scene with the state of the most recently saved score Debug.Log("Now loading: current_score_entry..."); // Update the current_score_entry_index based on the next_score_location or the loaded_score_summary_index if (next_score_location != null) { // Select the next score index based on the intended direction int relative_index_location = 0; if (next_score_location == "left") { relative_index_location = -1; } else if (next_score_location == "right") { relative_index_location = 1; } this.current_score_entry_index += relative_index_location; } else { this.current_score_entry_index = loaded_score_summary_index; } // Prevent IndexOutOfRangeException // Adjust the current_score_entry_index to make sure it's within the valid range of saved_score_entry_list if (this.current_score_entry_index <= 0) { // The oldest saved score has been loaded, so loop back to the newest one this.current_score_entry_index = this.saved_score_entry_list.Count - 1; } else if (this.current_score_entry_index >= this.saved_score_entry_list.Count) { // The newest saved score has been loaded, so loop back to the oldest one this.current_score_entry_index = 0; } Debug.LogFormat("this.current_score_entry_index = {0}", this.current_score_entry_index); this.current_score_entry = this.saved_score_entry_list[this.current_score_entry_index]; // loaded_score_summary is of type Dictionary<string, List<string>>, just like the toggle_name_dictionary if (loaded_score_summary == null && this.current_score_entry != null) { // This method can be optionally called with a score summary instance. If so, then load that instance's state into the scene. // If not, then use the most recently saved score summary, if it exists (i.e. this.current_score_entry). string loaded_score_summary_string = this.current_score_entry.score_summary; loaded_score_summary = JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(loaded_score_summary_string); } // Make sure there's a loaded score summary before trying to process it. It's null by default. if (loaded_score_summary != null) { // Reset the score first to prevent the score from duplicating on top of the current score in the scene this.ResetScore(); foreach (KeyValuePair <string, List <string> > toggle_name_list in loaded_score_summary) { // Debug.Log(string.Format("this is the key: {0}", toggle_name_list.Key)); string toggle_state_string = toggle_name_list.Key; // At this point, toggle_state_string should be either "checked" or "unchecked", depending on the current list // We will use toggle_state_string to set the new state of the toggle objects bool toggle_state = false; if (toggle_state_string == "checked") { toggle_state = true; } foreach (string toggle_name in toggle_name_list.Value) { // Debug.Log(toggle_name); // GameObject.Find() is slow, and apparently searches all available/active scenes // TODO: Create another solution for retrieving the toggle object by name // Toggle current_toggle = GameObject.Find(toggle_name).GetComponent<Toggle>(); // this.SetToggleState(current_toggle:current_toggle, is_on:toggle_state); Toggle current_toggle = this.toggle_name_dictionary[toggle_name]; this.SetToggleState(current_toggle: current_toggle, is_on: toggle_state); } // Update the score with the point value of this toggle if it was checked this.UpdateScoreText(); } } else { Debug.Log("Warning: You're attempting to load a score when one has not been provided. Try saving first with Control+Shift+R..."); } }