LoadLevelIfSynced
How do I use Load Level If Synced
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: NetworkingPeer.cs
Copy
3630 internal protected void LoadLevelIfSynced()
3631 {
3632 if (!PhotonNetwork.automaticallySyncScene || PhotonNetwork.isMasterClient || PhotonNetwork.room == null)
3633 {
3634 return;
3635 }
3636
3637 // check if "current level" is set in props
3638 if (!PhotonNetwork.room.customProperties.ContainsKey(NetworkingPeer.CurrentSceneProperty))
3639 {
3640 return;
3641 }
3642
3643 // if loaded level is not the one defined my master in props, load that level
3644 object sceneId = PhotonNetwork.room.customProperties[NetworkingPeer.CurrentSceneProperty];
3645 if (sceneId is int)
3646 {
3647 if (Application.loadedLevel != (int)sceneId)
3648 PhotonNetwork.LoadLevel((int)sceneId);
3649 }
3650 else if (sceneId is string)
3651 {
3652 if (Application.loadedLevelName != (string)sceneId)
3653 PhotonNetwork.LoadLevel((string)sceneId);
3654 }
3655 }
File name: PhotonHandler.cs
Copy
118 protected void OnJoinedRoom()
119 {
120 PhotonNetwork.networkingPeer.LoadLevelIfSynced();
121 }
File name: PhotonNetwork.cs
Copy
526 {
527 get
528 {
529 return _mAutomaticallySyncScene;
530 }
531 set
532 {
533 _mAutomaticallySyncScene = value;
534 if (_mAutomaticallySyncScene && room != null)
535 {
536 networkingPeer.LoadLevelIfSynced();
537 }
538 }
539 }
LoadLevelIfSynced 148 lượt xem
Gõ tìm kiếm nhanh...