/// <summary> /// Records the player's name and id to the chosen slot then saves the character to file /// </summary> public void SaveCharacterToFile(int slotNumber) { SaveSlot slot = SaveSlotRegistry.Instance.GetSlotAt(slotNumber); Debug.Assert(slot != null, "Invalid SaveSlot"); slot.isSlotOccupied = true; slot.playerName = this.character.Name; slot.playerId = this.character.Id.ToString(); SaveSlotRegistry.Instance.SaveTheSlots(); RpgCharacterSerializer.SaveCharacter(this.character); Debug.Log("The character \"" + this.character.Name + "\" was saved to Slot " + slotNumber.ToString()); this.RefreshUI(); }
/// <summary> /// Loads a player from file using the name and id of the player saved in the given slot. /// Returns true if the slot is not empty and the character was loaded /// </summary> /// <param name="slotNumber">Slot number.</param> public void LoadCharacterFromFile(int slotNumber) { SaveSlot slot = SaveSlotRegistry.Instance.GetSlotAt(slotNumber); Debug.Assert(slot != null, "Invalid SaveSlot"); if (slot.isSlotOccupied == false) { Debug.LogWarning("Save Slot " + slotNumber.ToString() + " is empty. No character was loaded."); return; } this.character = RpgCharacterSerializer.LoadCharacter(slot.playerName, slot.playerId); Debug.Assert(this.character != null, "Unknown Error when loading character from file! " + slot.playerName + " " + slot.playerId); Debug.Log("The character \"" + this.character.Name + "\" was loaded from Slot " + slotNumber.ToString()); this.RefreshUI(); }