Skip to content
Snippets Groups Projects
Commit 1915720b authored by jorobis's avatar jorobis
Browse files

Primera parte json

parent 8b57e7a1
No related branches found
No related tags found
No related merge requests found
......@@ -38,6 +38,7 @@ public class ControladorImagenes : MonoBehaviour
public ReconocedorKeywords reconocedorKeywords;
public ReconocedorDictation reconocedorDictation;
private void Start()
{
......@@ -273,4 +274,12 @@ public class ControladorImagenes : MonoBehaviour
SceneManager.LoadScene("EleccionFonema");
}
void OnApplicationQuit()
{
//Informacion.Instance.Save(PlayerPrefs.GetString("fonema"), string.Join("", imagenesAcertadas.Select(b => b ? "1" : "0")));
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using UnityEngine;
//Clase Singleton copia de la clase Escritor
public class Informacion : MonoBehaviour
{
private static Informacion instance;
private string nombreFichero = "";
private string filePath = "";
private string fileGameLog = "";
private bool generarGameLog = true;
private bool infoAdicional = false;
private string info = "";
Diccionario d = new Diccionario();
public static Informacion Instance
{
get
{
if (instance == null)
{
GameObject mySingletonObject = new GameObject("InformacionObject");
DontDestroyOnLoad(mySingletonObject);
instance = mySingletonObject.AddComponent<Informacion>();
}
return instance;
}
}
public void Save(string fonema, string aciertos)
{
GenerarFichero(fonema);
GameData data = new GameData()
{
fecha = DateTime.Now.ToString("dd-MM-yyyy"),
evento = aciertos,
hora = DateTime.Now.ToString("T"),
};
filePath = "./Jugador/Minijuegos/" + nombreFichero + ".json";
Debug.Log("Filepath:" + filePath);
setFilePath(filePath);
// Read existing json data
var jsonData = System.IO.File.ReadAllText(filePath);
// De-serialize to object or create new list
var employeeList = JsonConvert.DeserializeObject<List<GameData>>(jsonData)
?? new List<GameData>();
// Add any new employees
employeeList.Add(data);
// Update json data string
jsonData = JsonConvert.SerializeObject(employeeList, Formatting.Indented);
System.IO.File.WriteAllText(filePath, jsonData);
}
private void GenerarFichero(string ficheroDinamica)
{
string comprobacion = "./Jugador/Minijuegos/";
if (!File.Exists(comprobacion)) Directory.CreateDirectory(Path.GetDirectoryName(comprobacion));
string fecha = DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss");
nombreFichero = fecha + ficheroDinamica;
fileGameLog = nombreFichero;
var fs = new FileStream("./Jugador/Minijuegos/" + nombreFichero + ".json", FileMode.Create);
fs.Dispose();
string text = File.ReadAllText("./Jugador/Minijuegos/" + nombreFichero + ".json");
}
public string getFilePath()
{
return filePath;
}
private void setFilePath(string newFile)
{
filePath = newFile;
}
public void setGenerarGameLog(bool estado)
{
generarGameLog = estado;
}
public string getGameLog()
{
return nombreFichero;
}
public void setInfoAdicional(bool estado, string info)
{
infoAdicional = estado;
this.info = info;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment