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.

91 lines
2.2 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. public class NetworkedUIManager : PlayerUIManager
  8. {
  9. [SerializeField]
  10. private ClientObject Client;
  11. [SerializeField]
  12. private TMPro.TextMeshProUGUI TimeText;
  13. [SerializeField]
  14. private RectTransform Title;
  15. [SerializeField]
  16. private float TotalTime;
  17. [Header("Debug")]
  18. [SerializeField]
  19. private bool isTimePaused;
  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. OnClick_Show();
  30. }
  31. private void OnEnable()
  32. {
  33. if (Client.isConnected)
  34. Client.client.RegisterHandler(LogicProtocols.SendRoundTime, UpdateTime);
  35. }
  36. private void OnDisable()
  37. {
  38. if (Client.isConnected)
  39. Client.client.UnregisterHandler(LogicProtocols.SendRoundTime);
  40. }
  41. private void Update()
  42. {
  43. if (!isTimePaused)
  44. {
  45. TimeText.text = ((int)(TotalTime - (Time.time - StartTime))).ToString();
  46. if (Time.time - StartTime > TotalTime)
  47. OnClick_Play();
  48. }
  49. }
  50. public override void OnClick_Play()
  51. {
  52. OnClick_Hide();
  53. LogicProtocols.LogicMsg msg = new LogicProtocols.LogicMsg(reader.LogicChain.ToArray());
  54. Debug.Log("sending on " + LogicProtocols.SendLogicList);
  55. Client.client.SendByChannel(LogicProtocols.SendLogicList, msg, TransportConfigure.ReliableFragmented);
  56. UnityEngine.SceneManagement.SceneManager.LoadScene("WaitScene");
  57. }
  58. public void On_ClickPauseTime()
  59. {
  60. isTimePaused = !isTimePaused;
  61. if (isTimePaused)
  62. TimeText.color = Color.grey;
  63. else
  64. TimeText.color = Color.black;
  65. }
  66. public void UpdateTime(NetworkMessage msg)
  67. {
  68. LogicProtocols.FloatMsg floatMsg;
  69. if (!msg.TryRead(out floatMsg))
  70. return;
  71. TotalTime = floatMsg.Float;
  72. }
  73. }