Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/InRoomRoundTimer.cs
2026-02-21 16:45:37 +08:00

82 lines
1.8 KiB
C#

using ExitGames.Client.Photon;
using UnityEngine;
public class InRoomRoundTimer : MonoBehaviour
{
public int SecondsPerTurn = 5;
public double StartTime;
public Rect TextPos = new Rect(0f, 80f, 150f, 300f);
private bool startRoundWhenTimeIsSynced;
private const string StartTimeKey = "st";
private void StartRoundNow()
{
if (PhotonNetwork.time < 9.999999747378752E-05)
{
startRoundWhenTimeIsSynced = true;
return;
}
startRoundWhenTimeIsSynced = false;
Hashtable hashtable = new Hashtable();
hashtable["st"] = PhotonNetwork.time;
PhotonNetwork.room.SetCustomProperties(hashtable);
}
public void OnJoinedRoom()
{
if (PhotonNetwork.isMasterClient)
{
StartRoundNow();
}
else
{
Debug.Log("StartTime already set: " + PhotonNetwork.room.customProperties.ContainsKey("st"));
}
}
public void OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged)
{
if (propertiesThatChanged.ContainsKey("st"))
{
StartTime = (double)propertiesThatChanged["st"];
}
}
public void OnMasterClientSwitched(PhotonPlayer newMasterClient)
{
if (!PhotonNetwork.room.customProperties.ContainsKey("st"))
{
Debug.Log("The new master starts a new round, cause we didn't start yet.");
StartRoundNow();
}
}
private void Update()
{
if (startRoundWhenTimeIsSynced)
{
StartRoundNow();
}
}
public void OnGUI()
{
double num = PhotonNetwork.time - StartTime;
double num2 = (double)SecondsPerTurn - num % (double)SecondsPerTurn;
int num3 = (int)(num / (double)SecondsPerTurn);
GUILayout.BeginArea(TextPos);
GUILayout.Label(string.Format("elapsed: {0:0.000}", num));
GUILayout.Label(string.Format("remaining: {0:0.000}", num2));
GUILayout.Label(string.Format("turn: {0:0}", num3));
if (GUILayout.Button("new round"))
{
StartRoundNow();
}
GUILayout.EndArea();
}
}