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.

72 lines
2.0 KiB

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