104 lines
2.5 KiB
C#
104 lines
2.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class GameManager : MonoBehaviour {
|
|
private static GameManager _instance;
|
|
|
|
//public static GameManager Instance {get {return _instance; } }
|
|
public static GameManager Instance {get {return _instance ?? (_instance =
|
|
new GameObject("GameManager").AddComponent<GameManager>()); } }
|
|
|
|
private HUDManager hm;
|
|
private BikeManager bm1;
|
|
private BikeManager bm2;
|
|
|
|
// Skins of the two players
|
|
private int[] _skins = new int[2];
|
|
|
|
ConfigurationLoader conf;
|
|
|
|
private void Awake(){
|
|
// Singleton
|
|
if (_instance != null && _instance != this) {
|
|
Debug.Log("WARNING: Other instance of GameManager found.");
|
|
Destroy(gameObject);
|
|
} else {
|
|
_instance = this;
|
|
}
|
|
|
|
// Don't destroy when loading new scene
|
|
DontDestroyOnLoad(transform.gameObject);
|
|
|
|
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.");
|
|
}
|
|
|
|
public void RegisterBike(BikeManager bike, int bikeID) {
|
|
if (bikeID == 0)
|
|
bm1 = bike;
|
|
if (bikeID == 1)
|
|
bm2 = bike;
|
|
}
|
|
|
|
public void RegisterHUD(HUDManager hud) {
|
|
hm = hud;
|
|
}
|
|
|
|
public BikeManager GetBikeManager(int bikeID) {
|
|
if (bikeID == 0)
|
|
return bm1;
|
|
if (bikeID == 1)
|
|
return bm2;
|
|
return null;
|
|
}
|
|
|
|
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];
|
|
}
|
|
|
|
public int GetSensorsCount(int bikeID) {
|
|
return conf.sensors[bikeID];
|
|
}
|
|
|
|
public void SetSkins(int player1, int player2) {
|
|
_skins[0] = player1;
|
|
_skins[1] = player2;
|
|
}
|
|
|
|
public int GetSkins(int playerID) {
|
|
return _skins[playerID];
|
|
}
|
|
|
|
void Update() {
|
|
if (Input.GetButtonDown("SubmitP1")) {
|
|
Debug.Log("Héhé Cancel");
|
|
SetSkins(0, 0);
|
|
SceneManager.LoadScene("GameScene");
|
|
}
|
|
Debug.Log("azee");
|
|
}
|
|
}
|