Fichier de configuration ok
This commit is contained in:
parent
8ea04ad858
commit
a3be3d4aa2
@ -42,6 +42,9 @@ public class BikeManager : MonoBehaviour {
|
|||||||
gm = GameManager.Instance;
|
gm = GameManager.Instance;
|
||||||
gm.RegisterBike(this, playerID);
|
gm.RegisterBike(this, playerID);
|
||||||
|
|
||||||
|
distanceToRun = gm.GetRaceDistance();
|
||||||
|
Debug.Log("Hello ima stupid bike and i should go until " + gm.GetRaceDistance());
|
||||||
|
|
||||||
vm = gameObject.GetComponent<VideoManager>();
|
vm = gameObject.GetComponent<VideoManager>();
|
||||||
|
|
||||||
// TODO: Refactor w a player manager ?
|
// TODO: Refactor w a player manager ?
|
||||||
|
|||||||
40
Assets/Scripts/GameScene/ConfigurationLoader.cs
Normal file
40
Assets/Scripts/GameScene/ConfigurationLoader.cs
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
13
Assets/Scripts/GameScene/ConfigurationLoader.cs.meta
Normal file
13
Assets/Scripts/GameScene/ConfigurationLoader.cs.meta
Normal 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:
|
||||||
@ -1,5 +1,4 @@
|
|||||||
using System.IO;
|
using System.Collections;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -12,26 +11,28 @@ public class GameManager : MonoBehaviour {
|
|||||||
private BikeManager bm1;
|
private BikeManager bm1;
|
||||||
private BikeManager bm2;
|
private BikeManager bm2;
|
||||||
|
|
||||||
|
ConfigurationLoader conf;
|
||||||
|
|
||||||
private void Awake(){
|
private void Awake(){
|
||||||
|
// Singleton
|
||||||
if (_instance != null && _instance != this) {
|
if (_instance != null && _instance != this) {
|
||||||
Debug.Log("WARNING: Other instance of GameManager found.");
|
Debug.Log("WARNING: Other instance of GameManager found.");
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
} else {
|
} else {
|
||||||
_instance = this;
|
_instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conf = new ConfigurationLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
|
// Quick Check
|
||||||
if (hm == null)
|
if (hm == null)
|
||||||
Debug.Log("ERROR: HUDManager not registered.");
|
Debug.Log("ERROR: HUDManager not registered.");
|
||||||
if (bm1 == null)
|
if (bm1 == null)
|
||||||
Debug.Log("ERROR: BikeManager P1 not registered.");
|
Debug.Log("ERROR: BikeManager P1 not registered.");
|
||||||
if (bm2 == null)
|
if (bm2 == null)
|
||||||
Debug.Log("ERROR: BikeManager P2 not registered.");
|
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) {
|
public void RegisterBike(BikeManager bike, int bikeID) {
|
||||||
@ -56,4 +57,16 @@ public class GameManager : MonoBehaviour {
|
|||||||
public void Hello() {
|
public void Hello() {
|
||||||
Debug.Log("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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,23 @@
|
|||||||
{
|
{
|
||||||
"Race": {
|
"_comment": "
|
||||||
"Length": 300,
|
# Aide
|
||||||
"NormalTime": 30
|
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": {
|
"Vélos": {
|
||||||
"Bike0": {
|
"Joueur1": {
|
||||||
"WheelDiameter": 0.700,
|
"DiamètreRoue": 700,
|
||||||
"Captors": 4
|
"NombreDeCapteurs": 4
|
||||||
},
|
},
|
||||||
"Bike1": {
|
"Joueur2": {
|
||||||
"WheelDiameter": .700,
|
"DiamètreRoue": 700,
|
||||||
"Captors": 4
|
"NombreDeCapteurs": 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user