OnPhotonCustomRoomPropertiesChanged
How do I use On Photon Custom Room Properties Changed
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: NetworkingPeer.cs
Copy
530 // joins a room and sets your current username as custom actorproperty (will broadcast that)
536 private void ReadoutProperties(Hashtable gameProperties, Hashtable pActorProperties, int targetActorNr)
537 {
538 // Debug.LogWarning("ReadoutProperties gameProperties: " + gameProperties.ToStringFull() + " pActorProperties: " + pActorProperties.ToStringFull() + " targetActorNr: " + targetActorNr);
539 // read game properties and cache them locally
540 if (this.mCurrentGame != null && gameProperties != null)
541 {
542 this.mCurrentGame.CacheProperties(gameProperties);
543 SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, gameProperties);
544 if (PhotonNetwork.automaticallySyncScene)
545 {
546 this.LoadLevelIfSynced(); // will load new scene if sceneName was changed
547 }
548 }
549
550 if (pActorProperties != null && pActorProperties.Count > 0)
551 {
552 if (targetActorNr > 0)
553 {
554 // we have a single entry in the pActorProperties with one
555 // user's name
556 // targets MUST exist before you set properties
557 PhotonPlayer target = this.GetPlayerWithID(targetActorNr);
558 if (target != null)
559 {
560 Hashtable props = this.GetActorPropertiesForActorNr(pActorProperties, targetActorNr);
561 target.InternalCacheProperties(props);
562 SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, target, props);
563 }
564 }
565 else
566 {
567 // in this case, we've got a key-value pair per actor (each
568 // value is a hashtable with the actor's properties then)
569 int actorNr;
570 Hashtable props;
571 string newName;
572 PhotonPlayer target;
573
574 foreach (object key in pActorProperties.Keys)
575 {
576 actorNr = (int)key;
577 props = (Hashtable)pActorProperties[key];
578 newName = (string)props[ActorProperties.PlayerName];
579
580 target = this.GetPlayerWithID(actorNr);
581 if (target == null)
582 {
583 target = new PhotonPlayer(false, actorNr, newName);
584 this.AddNewPlayer(actorNr, target);
585 }
586
587 target.InternalCacheProperties(props);
588 SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, target, props);
589 }
590 }
591 }
592 }
File name: PhotonClasses.cs
Copy
644 public virtual void OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged)
645 {
646 }
File name: Room.cs
Copy
196 public void SetCustomProperties(Hashtable propertiesToSet)
197 {
198 if (propertiesToSet == null)
199 {
200 return;
201 }
202
203 // merge (delete null-values)
204 this.customProperties.MergeStringKeys(propertiesToSet); // includes a Equals check (simplifying things)
205 this.customProperties.StripKeysWithNullValues();
206
207
208 // send (sync) these new values
209 Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable;
210 if (!PhotonNetwork.offlineMode)
211 {
212 PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfRoom(customProps, true, 0);
213 }
214 NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, propertiesToSet);
215 }
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
63 public void OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged)
64 {
65 if (propertiesThatChanged.ContainsKey(StartTimeKey))
66 {
67 StartTime = (double)propertiesThatChanged[StartTimeKey];
68 }
69 }
OnPhotonCustomRoomPropertiesChanged 336 lượt xem
Gõ tìm kiếm nhanh...