You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.9 KiB

  1. using UnityEngine;
  2. using Networking;
  3. using Networking.Client;
  4. using UnityEngine.UI;
  5. public class NetworkedUIManager : PlayerUIManager
  6. {
  7. [SerializeField]
  8. private ClientObject Client;
  9. [SerializeField]
  10. private TMPro.TextMeshProUGUI TimeText;
  11. [SerializeField]
  12. private RectTransform Title;
  13. [SerializeField]
  14. private TMPro.TextMeshProUGUI LivesText;
  15. [Header("Debug")]
  16. [SerializeField]
  17. private bool isTimePaused;
  18. public Image backgroundColour;
  19. public Image animalSprite;
  20. private float StartTime;
  21. private BlockReader reader;
  22. protected override void Awake()
  23. {
  24. base.Awake();
  25. reader = new BlockReader();
  26. TrayUI.SetBlockReader(reader);
  27. StartTime = Time.time;
  28. ShowPosition.y -= Title.rect.height;
  29. LivesText.text = "Lives: " + Client.RemainingLives;
  30. //backgroundColour.color = Client.PlayerColor;
  31. animalSprite.sprite = Resources.Load<Sprite>(Client.PlayerAnimal.ToString());
  32. OnClick_Show();
  33. }
  34. private void Update()
  35. {
  36. if (!isTimePaused)
  37. {
  38. TimeText.text = ((int)(Client.RoundTime - (Time.time - StartTime))).ToString();
  39. if (Time.time - StartTime > Client.RoundTime)
  40. OnClick_Play();
  41. }
  42. }
  43. public override void OnClick_Play()
  44. {
  45. OnClick_Hide();
  46. LogicProtocols.LogicMsg msg = new LogicProtocols.LogicMsg(reader.LogicChain.ToArray());
  47. Debug.Log("sending on " + LogicProtocols.SendLogicList);
  48. Client.client.SendByChannel(LogicProtocols.SendLogicList, msg, TransportConfigure.ReliableFragmented);
  49. UnityEngine.SceneManagement.SceneManager.LoadScene("WaitScene");
  50. }
  51. public void On_ClickPauseTime()
  52. {
  53. isTimePaused = !isTimePaused;
  54. if (isTimePaused)
  55. TimeText.color = Color.grey;
  56. else
  57. TimeText.color = Color.black;
  58. }
  59. }