Fichier de configuration ok

This commit is contained in:
Florent Guiotte 2018-03-12 23:24:25 +01:00
parent 8ea04ad858
commit a3be3d4aa2
5 changed files with 92 additions and 16 deletions

View File

@ -42,6 +42,9 @@ public class BikeManager : MonoBehaviour {
gm = GameManager.Instance;
gm.RegisterBike(this, playerID);
distanceToRun = gm.GetRaceDistance();
Debug.Log("Hello ima stupid bike and i should go until " + gm.GetRaceDistance());
vm = gameObject.GetComponent<VideoManager>();
// TODO: Refactor w a player manager ?

View File

@ -0,0 +1,40 @@
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 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;
}
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");
}
}

View File

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: e723423e650814b4a99445268b07d57e
timeCreated: 1520890784
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,5 +1,4 @@
using System.IO;
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@ -12,26 +11,28 @@ public class GameManager : MonoBehaviour {
private BikeManager bm1;
private BikeManager bm2;
ConfigurationLoader conf;
private void Awake(){
// Singleton
if (_instance != null && _instance != this) {
Debug.Log("WARNING: Other instance of GameManager found.");
Destroy(gameObject);
} else {
_instance = this;
}
conf = new ConfigurationLoader();
}
private void Start() {
// Quick Check
if (hm == null)
Debug.Log("ERROR: HUDManager not registered.");
if (bm1 == null)
Debug.Log("ERROR: BikeManager P1 not registered.");
if (bm2 == null)
Debug.Log("ERROR: BikeManager P2 not registered.");
var sr = new StreamReader(Application.streamingAssetsPath + "/config.json");
JSONObject obj = new JSONObject(sr.ReadToEnd());
Debug.Log(obj["Race"]["Length"]);
}
public void RegisterBike(BikeManager bike, int bikeID) {
@ -56,4 +57,16 @@ public class GameManager : MonoBehaviour {
public void Hello() {
Debug.Log("Hello!");
}
public float GetRaceDistance() {
return conf.distance;
}
public float GetRaceNormalTime() {
return conf.normalTime;
}
public float GetBikeWheelDiameter(int bikeID) {
return conf.diameters[bikeID];
}
}

View File

@ -1,16 +1,23 @@
{
"Race": {
"Length": 300,
"NormalTime": 30
"_comment": "
# Aide
Distance: La distance de la course en mètre
TempsNormal: Le temps attendu de la course en seconde
DiamètreRoue: Le diamètres des roues en millimètre
NombreDeCapteurs: Le nombre de capteurs placés sur la roue du vélo
",
"Course": {
"Distance": 300,
"TempsNormal": 30
},
"Bikes": {
"Bike0": {
"WheelDiameter": 0.700,
"Captors": 4
"Vélos": {
"Joueur1": {
"DiamètreRoue": 700,
"NombreDeCapteurs": 4
},
"Bike1": {
"WheelDiameter": .700,
"Captors": 4
"Joueur2": {
"DiamètreRoue": 700,
"NombreDeCapteurs": 4
}
}
}