SetLevelInPropsIfSynced
How do I use Set Level In Props If Synced
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: NetworkingPeer.cs
Copy
3657 protected internal void SetLevelInPropsIfSynced(object levelId)
3658 {
3659 if (!PhotonNetwork.automaticallySyncScene || !PhotonNetwork.isMasterClient || PhotonNetwork.room == null)
3660 {
3661 return;
3662 }
3663 if (levelId == null)
3664 {
3665 Debug.LogError("Parameter levelId can't be null!");
3666 return;
3667 }
3668
3669 // check if "current level" is already set in props
3670 if (PhotonNetwork.room.customProperties.ContainsKey(NetworkingPeer.CurrentSceneProperty))
3671 {
3672 object levelIdInProps = PhotonNetwork.room.customProperties[NetworkingPeer.CurrentSceneProperty];
3673 if (levelIdInProps is int && Application.loadedLevel == (int)levelIdInProps)
3674 {
3675 return;
3676 }
3677 if (levelIdInProps is string && Application.loadedLevelName.Equals((string)levelIdInProps))
3678 {
3679 return;
3680 }
3681 }
3682
3683 // current level is not yet in props, so this client has to set it
3684 Hashtable setScene = new Hashtable();
3685 if (levelId is int) setScene[NetworkingPeer.CurrentSceneProperty] = (int)levelId;
3686 else if (levelId is string) setScene[NetworkingPeer.CurrentSceneProperty] = (string)levelId;
3687 else Debug.LogError("Parameter levelId must be int or string!");
3688
3689 PhotonNetwork.room.SetCustomProperties(setScene);
3690 this.SendOutgoingCommands(); // send immediately! because: in most cases the client will begin to load and not send for a while
3691 }
File name: PhotonHandler.cs
Copy
112 protected void OnLevelWasLoaded(int level)
113 {
114 PhotonNetwork.networkingPeer.NewSceneLoaded();
115 PhotonNetwork.networkingPeer.SetLevelInPropsIfSynced(Application.loadedLevelName);
116 }
File name: PhotonHandler.cs
Copy
123 protected void OnCreatedRoom()
124 {
125 PhotonNetwork.networkingPeer.SetLevelInPropsIfSynced(Application.loadedLevelName);
126 }
File name: PhotonNetwork.cs
Copy
2652 public static void LoadLevel(int levelNumber)
2653 {
2654 networkingPeer.SetLevelInPropsIfSynced(levelNumber);
2655
2656 PhotonNetwork.isMessageQueueRunning = false;
2657 networkingPeer.loadingLevelAndPausedNetwork = true;
2658 Application.LoadLevel(levelNumber);
2659 }
File name: PhotonNetwork.cs
Copy
2678 public static void LoadLevel(string levelName)
2679 {
2680 networkingPeer.SetLevelInPropsIfSynced(levelName);
2681
2682 PhotonNetwork.isMessageQueueRunning = false;
2683 networkingPeer.loadingLevelAndPausedNetwork = true;
2684 Application.LoadLevel(levelName);
2685 }
SetLevelInPropsIfSynced 132 lượt xem
Gõ tìm kiếm nhanh...