CurrentSceneProperty









How do I use Current Scene Property
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


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: 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     }

CurrentSceneProperty 116 lượt xem

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