Import() { Debug.Log("importing phenotypes..."); if (File.Exists("phenotypes.neat")) { string json = File.ReadAllText("phenotypes.neat"); SerializablePhenotypes serializablePhenotypes = JsonUtility.FromJson <SerializablePhenotypes> (json); if (serializablePhenotypes.phenotypes.Count != brains.Count) { Debug.LogError("phenotypes and genomes mismatch error. (" + serializablePhenotypes.phenotypes.Count + " / " + brains.Count + ")"); return; } this.phenotypes = serializablePhenotypes.phenotypes; for (int i = 0; i < brains.Count; i++) { CarBrain brain = brains[i]; brain.AssignPhenotype(phenotypes[i]); brain.runOnlyMode = true; brain.Reset(); } runOnlyMode = true; } }
Export() { if (phenotypes == null) { return; } Debug.Log("exporting phenotypes..."); SerializablePhenotypes serializablePhenotypes = new SerializablePhenotypes { phenotypes = this.phenotypes }; string json = JsonUtility.ToJson(serializablePhenotypes); File.WriteAllText("phenotypes.neat", json); json = JsonUtility.ToJson(bestPhenotype); File.WriteAllText("best.neat", json); }