A easy and fast way to save a lot of vars in Unity
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