A easy and fast way to save a lot of vars in Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class SaveData : MonoBehaviour | |
{ | |
public SAVEDATACLASS progreso; //es visible desde Inspector | |
public void Guardar() | |
{ | |
//Generamos el formato Json | |
string Archivo = JsonUtility.ToJson(progreso); | |
//Lo guardamos con PlayerPrefs | |
PlayerPrefs.SetString("KeySave", Archivo); | |
} | |
public void Cargar() | |
{ | |
string Archivo = PlayerPrefs.GetString("KeySave"); | |
//Solo seguridad que si exista algo | |
if (!string.IsNullOrEmpty(Archivo)) | |
{ | |
progreso= JsonUtility.FromJson<SAVEDATACLASS>(Archivo); | |
} | |
} | |
} | |
[System.Serializable] | |
public class SAVEDATACLASS | |
{ | |
public int UnInt; | |
public string UnString; | |
public float UnFloat; | |
public bool UnBool; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment