105 lines
2.7 KiB
C#
105 lines
2.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
|
|
public class HUDManager : MonoBehaviour {
|
|
|
|
public GameObject[] flags;
|
|
public GameObject[] highScores;
|
|
public Text[] chronos;
|
|
public Text[] firsts;
|
|
public Text[] tachometers;
|
|
public Text[] maxSpeeds;
|
|
//public HUDProgress[] progressions;
|
|
public Transform[] progressions;
|
|
public Text[] distances;
|
|
[SerializeField]
|
|
private GameObject[] _messages;
|
|
public GameObject[] Messages {get {return _messages;} }
|
|
|
|
public GameObject loadingScreens;
|
|
|
|
private float[] maxSpeedsValues = new float[2];
|
|
|
|
GameManager gm;
|
|
|
|
void Awake() {
|
|
gm = GameManager.Instance;
|
|
gm.RegisterHUD(this);
|
|
}
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
for (int i = 0; i < 2; i++) {
|
|
UpdateSpeeds (i);
|
|
UpdateProgress (i);
|
|
UpdateDistance (i);
|
|
UpdateChrono (i);
|
|
UpdateFlags (i);
|
|
}
|
|
// UpdateFirst (0);
|
|
}
|
|
|
|
void UpdateFirst(int bikeID) {
|
|
firsts [bikeID].text = (gm.GetFirst () + 1).ToString();
|
|
}
|
|
|
|
void UpdateFlags(int bikeID) {
|
|
flags [bikeID].SetActive (gm.GetFirst () == bikeID);
|
|
}
|
|
|
|
void UpdateChrono(int bikeID) {
|
|
float time = gm.GetChrono ();
|
|
TimeSpan timeSpan = TimeSpan.FromSeconds(time);
|
|
chronos [bikeID].text = string.Format("{0:D2}:{1:D2}:{2:D2}", timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds / 10);
|
|
}
|
|
|
|
void UpdateDistance(int bikeID) {
|
|
distances[bikeID].text = gm.GetBikeManager(bikeID).GetDistance().ToString("#0") + "m";
|
|
|
|
}
|
|
|
|
void UpdateProgress(int bikeID) {
|
|
//progressions[bikeID].SetProgress(gm.GetBikeManager(bikeID).GetProgress());
|
|
progressions[bikeID].gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(gm.GetBikeManager(bikeID).GetProgress() * 600, 5);
|
|
}
|
|
|
|
void UpdateSpeeds(int bikeID) {
|
|
float s = gm.GetBikeManager(bikeID).GetSpeed();
|
|
|
|
if (s > maxSpeedsValues[bikeID])
|
|
maxSpeedsValues[bikeID] = s;
|
|
|
|
tachometers[bikeID].text = (s * 3.6f).ToString("#0.0") + "km/h";
|
|
maxSpeeds[bikeID].text = "Max : " + (maxSpeedsValues[bikeID] * 3.6f).ToString("#0.0");
|
|
}
|
|
|
|
public void SetMessageActive(bool status, int playerID=2) {
|
|
if (playerID > 1) {
|
|
Messages [0].SetActive (status);
|
|
// Messages[1].SetActive(status);
|
|
} else {
|
|
Messages [playerID].SetActive (status);
|
|
}
|
|
}
|
|
|
|
public void SetMessage(string message, int playerID=2) {
|
|
if (playerID > 1) {
|
|
Messages [0].GetComponent<Text> ().text = message;
|
|
// Messages[1].GetComponent<Text>().text = message;
|
|
} else {
|
|
Messages [playerID].GetComponent<Text> ().text = message;
|
|
}
|
|
}
|
|
|
|
public void SetHighScore(int playerID) {
|
|
highScores [playerID].SetActive (true);
|
|
}
|
|
}
|