StartTimeKey









How do I use Start Time Key
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


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
63     public void OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged)
64     {
65         if (propertiesThatChanged.ContainsKey(StartTimeKey))
66         {
67             StartTime = (double)propertiesThatChanged[StartTimeKey];
68         }
69     }
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     }

StartTimeKey 136 lượt xem

Gõ tìm kiếm nhanh...