Пример #1
0
    public static void WriteToFile(string uuid, int gen, ForceDNA.Genome[] genomes, float[] scores)
    {
        JSONGenome[] jgs = new JSONGenome[genomes.Length];
        for (int i = 0; i < genomes.Length; i++)
        {
            jgs [i] = new JSONGenome(genomes [i], scores [i]);
        }
        JSONGeneration jge  = new JSONGeneration(jgs);
        string         path = getPath(uuid, gen, true);
        string         json = JsonUtility.ToJson(jge, true);

        File.WriteAllLines(path, new string[] { json });
    }
Пример #2
0
    public static ForceDNA.Genome[] ReadFromFile(string uuid, int gen)
    {
        string path = getPath(uuid, gen, false);

        // This text is added only once to the file.
        if (!File.Exists(path))
        {
            return(null);
        }
        // Open the file to read from.
        string readText = File.ReadAllText(path);

        Debug.Log(readText);
        JSONGeneration jge = JsonUtility.FromJson <JSONGeneration>(readText);

        Debug.Log(jge);
        return(jge.ToGenomes());
    }