gold_sprint_lpr/Assets/Scripts/GameScene/ConfigurationLoader.cs

50 lines
1.7 KiB
C#

using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ConfigurationLoader {
private string filename = Application.streamingAssetsPath + "/config.json";
public float distance;
public float normalTime;
public float[] diameters = new float[2];
public int[] sensors = new int[2];
public float[] videoEnds = new float[8];
public ConfigurationLoader() {
Load();
Check();
}
private void Load() {
var sr = new StreamReader(Application.streamingAssetsPath + "/config.json");
var obj = new JSONObject(sr.ReadToEnd());
distance = obj["Course"]["Distance"].n;
normalTime = obj["Course"]["TempsNormal"].n;
diameters[0] = obj["Vélos"]["Joueur1"]["DiamètreRoue"].n / 1000f;
diameters[1] = obj["Vélos"]["Joueur2"]["DiamètreRoue"].n / 1000f;
sensors[0] = (int) obj["Vélos"]["Joueur1"]["NombreDeCapteurs"].n;
sensors[1] = (int) obj["Vélos"]["Joueur2"]["NombreDeCapteurs"].n;
for (int i = 0; i < 8; i++) {
videoEnds[i] = obj["Vidéos"][i]["Fin"].n;
Debug.Log("Video " + i + " end: " + videoEnds[i]);
}
}
private void Check() {
// TODO: Throw ? Fallback ?
if (distance < .01f)
Debug.Log("WARNING ConfigurationLoader: Distance is 0");
if (normalTime < .01f)
Debug.Log("WARNING ConfigurationLoader: NormalTime is 0");
if (diameters[0] < .001f)
Debug.Log("WARNING ConfigurationLoader: Diameter for player 1 is 0");
if (diameters[1] < .001f)
Debug.Log("WARNING ConfigurationLoader: Diameter for player 2 is 0");
}
}