StartRoundNow
How do I use Start Round Now
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
28 | private void StartRoundNow() | 1 |
53 | this.StartRoundNow(); | 2 |
81 | this.StartRoundNow(); | 3 |
90 | this.StartRoundNow(); // the "time is known" check is done inside the method. | 4 |
110 | this.StartRoundNow(); | 5 |
File name: InRoomRoundTimer.cs
Copy
28 private void StartRoundNow()
29 {
30 // in some cases, when you enter a room, the server time is not available immediately.
31 // time should be 0.0f but to make sure we detect it correctly, check for a very low value.
32 if (PhotonNetwork.time < 0.0001f)
33 {
34 // we can only start the round when the time is available. let's check that in Update()
35 startRoundWhenTimeIsSynced = true;
36 return;
37 }
38 startRoundWhenTimeIsSynced = false;
39
40
41
42 ExitGames.Client.Photon.Hashtable startTimeProp = new Hashtable(); // only use ExitGames.Client.Photon.Hashtable for Photon
43 startTimeProp[StartTimeKey] = PhotonNetwork.time;
44 PhotonNetwork.room.SetCustomProperties(startTimeProp); // implement OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged) to get this change everywhere
45 }
File name: InRoomRoundTimer.cs
Copy
49 public void OnJoinedRoom()
50 {
51 if (PhotonNetwork.isMasterClient)
52 {
53 this.StartRoundNow();
54 }
55 else
56 {
57 // as the creator of the room sets the start time after entering the room, we may enter a room that has no timer started yet
58 Debug.Log("StartTime already set: " + PhotonNetwork.room.customProperties.ContainsKey(StartTimeKey));
59 }
60 }
File name: InRoomRoundTimer.cs
Copy
76 public void OnMasterClientSwitched(PhotonPlayer newMasterClient)
77 {
78 if (!PhotonNetwork.room.customProperties.ContainsKey(StartTimeKey))
79 {
80 Debug.Log("The new master starts a new round, cause we didn't start yet.");
81 this.StartRoundNow();
82 }
83 }
File name: InRoomRoundTimer.cs
Copy
86 void Update()
87 {
88 if (startRoundWhenTimeIsSynced)
89 {
90 this.StartRoundNow(); // the "time is known" check is done inside the method.
91 }
92 }
File name: InRoomRoundTimer.cs
Copy
94 public void OnGUI()
95 {
96 // alternatively to doing this calculation here:
97 // calculate these values in Update() and make them publicly available to all other scripts
98 double elapsedTime = (PhotonNetwork.time - StartTime);
99 double remainingTime = SecondsPerTurn - (elapsedTime % SecondsPerTurn);
100 int turn = (int)(elapsedTime / SecondsPerTurn);
101
102
103 // simple gui for output
104 GUILayout.BeginArea(TextPos);
105 GUILayout.Label(string.Format("elapsed: {0:0.000}", elapsedTime));
106 GUILayout.Label(string.Format("remaining: {0:0.000}", remainingTime));
107 GUILayout.Label(string.Format("turn: {0:0}", turn));
108 if (GUILayout.Button("new round"))
109 {
110 this.StartRoundNow();
111 }
112 GUILayout.EndArea();
113 }
StartRoundNow 131 lượt xem
Gõ tìm kiếm nhanh...