139 lines
3.8 KiB
C#
139 lines
3.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
|
|
public class HUDManager : MonoBehaviour {
|
|
|
|
public GameObject[] flagsP1;
|
|
public GameObject[] flagsP2;
|
|
public GameObject[] highScores;
|
|
public Image[] transportsP1;
|
|
public Image[] transportsP2;
|
|
public Text[] chronos;
|
|
public Text[] tachometersP1;
|
|
public Text[] tachometersP2;
|
|
public Text[] maxSpeedsP1;
|
|
public Text[] maxSpeedsP2;
|
|
//public HUDProgress[] progressions;
|
|
public Transform[] progressionsP1;
|
|
public Transform[] progressionsP2;
|
|
public Text[] distancesP1;
|
|
public Text[] distancesP2;
|
|
[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);
|
|
|
|
//for (int i = 0; i < totalDistances.Length; i++)
|
|
// totalDistances [i] = gm.GetRaceDistance ();
|
|
}
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
for (int i = 0; i < 2; i++) {
|
|
transportsP1[i].sprite = gm.Transports320 [gm.GetSkins (0)];
|
|
transportsP2[i].sprite = gm.Transports320 [gm.GetSkins (1)];
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
UpdateSpeeds ();
|
|
UpdateProgress ();
|
|
UpdateDistance ();
|
|
UpdateChrono (0);
|
|
UpdateChrono (1);
|
|
UpdateFlags ();
|
|
}
|
|
|
|
void UpdateFlags() {
|
|
for (int i = 0; i < 2; i++) {
|
|
flagsP1 [i].SetActive (gm.GetFirst () == 0);
|
|
flagsP2 [i].SetActive (gm.GetFirst () == 1);
|
|
}
|
|
}
|
|
|
|
public void SetActiveChrono(bool active) {
|
|
chronos [0].gameObject.SetActive (active);
|
|
chronos [1].gameObject.SetActive (active);
|
|
}
|
|
|
|
void UpdateChrono(int bikeID) {
|
|
if (gm.Status != States.Race) {
|
|
chronos [bikeID].text = "00:00:00";
|
|
return;
|
|
}
|
|
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() {
|
|
for (int i = 0; i < 2; i++) {
|
|
distancesP1 [i].text = gm.GetBikeManager (0).GetDistance ().ToString ("#0") + "m / " + gm.GetRaceDistance() + "m";
|
|
distancesP2 [i].text = gm.GetBikeManager (1).GetDistance ().ToString ("#0") + "m / " + gm.GetRaceDistance() + "m";
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void UpdateProgress() {
|
|
for (int i = 0; i < 2; i++) {
|
|
progressionsP1 [i].gameObject.GetComponent<RectTransform> ().sizeDelta = new Vector2 (gm.GetBikeManager (0).GetProgress () * 600, 5);
|
|
progressionsP2 [i].gameObject.GetComponent<RectTransform> ().sizeDelta = new Vector2 (gm.GetBikeManager (1).GetProgress () * 600, 5);
|
|
}
|
|
}
|
|
|
|
void UpdateSpeeds() {
|
|
float s1 = gm.GetBikeManager (0).GetSpeed ();
|
|
float s2 = gm.GetBikeManager (1).GetSpeed ();
|
|
|
|
if (s1 > maxSpeedsValues [0])
|
|
maxSpeedsValues [0] = s1;
|
|
|
|
if (s2 > maxSpeedsValues [1])
|
|
maxSpeedsValues [1] = s2;
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
tachometersP1 [i].text = (s1 * 3.6f).ToString ("#0.0") + "km/h";
|
|
tachometersP2 [i].text = (s2 * 3.6f).ToString ("#0.0") + "km/h";
|
|
|
|
maxSpeedsP1 [i].text = "Max : " + (maxSpeedsValues [0] * 3.6f).ToString ("#0.0");
|
|
maxSpeedsP2 [i].text = "Max : " + (maxSpeedsValues [1] * 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);
|
|
}
|
|
}
|