Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

     protected internal void SetLevelInPropsIfSynced(object levelId)
     {
         if (!PhotonNetwork.automaticallySyncScene || !PhotonNetwork.isMasterClient || PhotonNetwork.room == null)
         {
             return;
         }
         if (levelId == null)
         {
             Debug.LogError("Parameter levelId can't be null!");
             return;
         }

         // check if "current level" is already set in props
         if (PhotonNetwork.room.customProperties.ContainsKey(NetworkingPeer.CurrentSceneProperty))
         {
             object levelIdInProps = PhotonNetwork.room.customProperties[NetworkingPeer.CurrentSceneProperty];
             if (levelIdInProps is int && Application.loadedLevel == (int)levelIdInProps)
             {
                 return;
             }
             if (levelIdInProps is string && Application.loadedLevelName.Equals((string)levelIdInProps))
             {
                 return;
             }
         }

         // current level is not yet in props, so this client has to set it
         Hashtable setScene = new Hashtable();
         if (levelId is int) setScene[NetworkingPeer.CurrentSceneProperty] = (int)levelId;
         else if (levelId is string) setScene[NetworkingPeer.CurrentSceneProperty] = (string)levelId;
         else Debug.LogError("Parameter levelId must be int or string!");

         PhotonNetwork.room.SetCustomProperties(setScene);
         this.SendOutgoingCommands(); // send immediately! because: in most cases the client will begin to load and not send for a while
     }