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:

     // joins a room and sets your current username as custom actorproperty (will broadcast that)
     private void ReadoutProperties(Hashtable gameProperties, Hashtable pActorProperties, int targetActorNr)
     {
         // Debug.LogWarning("ReadoutProperties gameProperties: " + gameProperties.ToStringFull() + " pActorProperties: " + pActorProperties.ToStringFull() + " targetActorNr: " + targetActorNr);
         // read game properties and cache them locally
         if (this.mCurrentGame != null && gameProperties != null)
         {
             this.mCurrentGame.CacheProperties(gameProperties);
             SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, gameProperties);
             if (PhotonNetwork.automaticallySyncScene)
             {
                 this.LoadLevelIfSynced(); // will load new scene if sceneName was changed
             }
         }

         if (pActorProperties != null && pActorProperties.Count > 0)
         {
             if (targetActorNr > 0)
             {
                 // we have a single entry in the pActorProperties with one
                 // user's name
                 // targets MUST exist before you set properties
                 PhotonPlayer target = this.GetPlayerWithID(targetActorNr);
                 if (target != null)
                 {
                     Hashtable props = this.GetActorPropertiesForActorNr(pActorProperties, targetActorNr);
                     target.InternalCacheProperties(props);
                     SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, target, props);
                 }
             }
             else
             {
                 // in this case, we've got a key-value pair per actor (each
                 // value is a hashtable with the actor's properties then)
                 int actorNr;
                 Hashtable props;
                 string newName;
                 PhotonPlayer target;

                 foreach (object key in pActorProperties.Keys)
                 {
                     actorNr = (int)key;
                     props = (Hashtable)pActorProperties[key];
                     newName = (string)props[ActorProperties.PlayerName];

                     target = this.GetPlayerWithID(actorNr);
                     if (target == null)
                     {
                         target = new PhotonPlayer(false, actorNr, newName);
                         this.AddNewPlayer(actorNr, target);
                     }

                     target.InternalCacheProperties(props);
                     SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, target, props);
                 }
             }
         }
     }