Browse Source

fixed Client time

Josh_Dev_branch
JoshuaReason 5 years ago
parent
commit
bab4dda14b
2 changed files with 23 additions and 24 deletions
  1. +20
    -0
      Assets/Scripts/Networking/Client/ClientObject.cs
  2. +3
    -24
      Assets/Scripts/UI/NetworkedUIManager.cs

+ 20
- 0
Assets/Scripts/Networking/Client/ClientObject.cs View File

@ -40,6 +40,15 @@ namespace Networking.Client
[SerializeField]
[Tooltip("Client Inventory")]
protected Inventory Inventory;
[SerializeField]
[Tooltip("Current Time in Round")]
public float RoundTime;
[SerializeField]
[Tooltip("Current Score in Round")]
public float RoundScore;
#endregion Inspector Fields
@ -64,6 +73,7 @@ namespace Networking.Client
client.RegisterHandler(LogicProtocols.SendInventory, RecieveInventory);
client.RegisterHandler(LoginProtocols.SceneChange, RecieveSceneChange);
client.RegisterHandler(MsgType.Disconnect, OnDisconnect);
client.RegisterHandler(LogicProtocols.SendRoundTime, UpdateTime);
}
public void Stop()
@ -105,6 +115,16 @@ namespace Networking.Client
{
UnityEngine.SceneManagement.SceneManager.LoadScene(DisconnectScene);
}
public void UpdateTime(NetworkMessage msg)
{
Debug.Log("Recieveing time from server");
LogicProtocols.FloatMsg floatMsg;
if (!msg.TryRead(out floatMsg))
return;
RoundTime = floatMsg.Float;
}
}
}

+ 3
- 24
Assets/Scripts/UI/NetworkedUIManager.cs View File

@ -14,9 +14,6 @@ public class NetworkedUIManager : PlayerUIManager
[SerializeField]
private RectTransform Title;
[SerializeField]
private float TotalTime;
[Header("Debug")]
[SerializeField]
private bool isTimePaused;
@ -35,25 +32,14 @@ public class NetworkedUIManager : PlayerUIManager
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();
TimeText.text = ((int)(Client.RoundTime - (Time.time - StartTime))).ToString();
if (Time.time - StartTime > TotalTime)
if (Time.time - StartTime > Client.RoundTime)
OnClick_Play();
}
}
@ -79,13 +65,6 @@ public class NetworkedUIManager : PlayerUIManager
}
public void UpdateTime(NetworkMessage msg)
{
LogicProtocols.FloatMsg floatMsg;
if (!msg.TryRead(out floatMsg))
return;
TotalTime = floatMsg.Float;
}
}

Loading…
Cancel
Save