Created
March 3, 2017 05:15
-
-
Save arkms/daece54b588585884df97693eb44ac73 to your computer and use it in GitHub Desktop.
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