-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatchTimer.cs
More file actions
71 lines (60 loc) · 2.07 KB
/
MatchTimer.cs
File metadata and controls
71 lines (60 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.IO;
using ExitGames.Client.Photon;
using Photon;
using UnityEngine;
public class MatchTimer : PunBehaviour
{
private const string TimeToStartProp = "st";
private double timeToStart = 0.0f;
public double SecondsBeforeStart = 10.0f; // set in inspector
public bool IsItTimeYet
{
get { return IsTimeToStartKnown && PhotonNetwork.time > this.timeToStart; }
}
public bool IsTimeToStartKnown
{
get { return this.timeToStart > 0.001f; }
}
public double SecondsUntilItsTime
{
get
{
if (this.IsTimeToStartKnown)
{
double delta = this.timeToStart - PhotonNetwork.time;
return (delta > 0.0f) ? delta : 0.0f;
}
else
{
return 0.0f;
}
}
}
void Update()
{
if (PhotonNetwork.isMasterClient)
{
// the master client checks if a start time is set. we check a min value
if (!this.IsTimeToStartKnown && PhotonNetwork.time > 0.0001f)
{
// no startTime set for room. calculate and set it as property of this room
this.timeToStart = PhotonNetwork.time + SecondsBeforeStart;
Hashtable timeProps = new Hashtable() { { TimeToStartProp, this.timeToStart } };
PhotonNetwork.room.SetCustomProperties(timeProps);
}
}
}
public override void OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged)
{
if (propertiesThatChanged.ContainsKey(TimeToStartProp))
{
this.timeToStart = (double)propertiesThatChanged[TimeToStartProp];
Debug.Log("Got StartTime: " + this.timeToStart + " is it time yet?! " + this.IsItTimeYet);
}
}
void OnGUI()
{
GUILayout.Label("Is it time yet: " + this.IsItTimeYet);
GUILayout.Label("Seconds until it's time: " + (float)this.SecondsUntilItsTime);
}
}