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[] 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 () { } // Update is called once per frame void Update () { UpdateSpeeds (); UpdateProgress (); UpdateDistance (); UpdateChrono (0); UpdateChrono (1); UpdateFlags (0); UpdateFlags (1); // UpdateFirst (0); } void UpdateFirst(int bikeID) { firsts [bikeID].text = (gm.GetFirst () + 1).ToString(); } void UpdateFlags(int bikeID) { flags [bikeID].SetActive (gm.GetFirst () == bikeID); } public void SetActiveChrono(bool active) { chronos [0].gameObject.SetActive (active); chronos [1].gameObject.SetActive (active); } 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() { 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 ().sizeDelta = new Vector2 (gm.GetBikeManager (0).GetProgress () * 600, 5); progressionsP2 [i].gameObject.GetComponent ().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 = message; // Messages[1].GetComponent().text = message; } else { Messages [playerID].GetComponent ().text = message; } } public void SetHighScore(int playerID) { highScores [playerID].SetActive (true); } }