using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using Networking; using Networking.Client; public class NetworkedUIManager : PlayerUIManager { [SerializeField] private ClientObject Client; [SerializeField] private TMPro.TextMeshProUGUI TimeText; [SerializeField] private RectTransform Title; [SerializeField] private float TotalTime; [Header("Debug")] [SerializeField] private bool isTimePaused; private float StartTime; private BlockReader reader; protected override void Awake() { base.Awake(); reader = new BlockReader(); TrayUI.SetBlockReader(reader); StartTime = Time.time; ShowPosition.y -= Title.rect.height; OnClick_Show(); } private void OnEnable() { if (Client.isConnected) Client.client.RegisterHandler(LogicProtocols.SendRoundTime, UpdateTime); } private void OnDisable() { if (Client.isConnected) Client.client.UnregisterHandler(LogicProtocols.SendRoundTime); } private void Update() { if (!isTimePaused) { TimeText.text = ((int)(TotalTime - (Time.time - StartTime))).ToString(); if (Time.time - StartTime > TotalTime) OnClick_Play(); } } public override void OnClick_Play() { OnClick_Hide(); LogicProtocols.LogicMsg msg = new LogicProtocols.LogicMsg(reader.LogicChain.ToArray()); Debug.Log("sending on " + LogicProtocols.SendLogicList); Client.client.SendByChannel(LogicProtocols.SendLogicList, msg, TransportConfigure.ReliableFragmented); UnityEngine.SceneManagement.SceneManager.LoadScene("WaitScene"); } public void On_ClickPauseTime() { isTimePaused = !isTimePaused; if (isTimePaused) TimeText.color = Color.grey; else TimeText.color = Color.black; } public void UpdateTime(NetworkMessage msg) { LogicProtocols.FloatMsg floatMsg; if (!msg.TryRead(out floatMsg)) return; TotalTime = floatMsg.Float; } }