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:

     private void HandleEventLeave(int actorID)
     {
         if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
             Debug.Log("HandleEventLeave for player ID: " + actorID);


         // actorNr is fetched out of event above
         if (actorID < 0 || !this.mActors.ContainsKey(actorID))
         {
             Debug.LogError(String.Format("Received event Leave for unknown player ID: {0}", actorID));
             return;
         }

         PhotonPlayer player = this.GetPlayerWithID(actorID);
         if (player == null)
         {
             Debug.LogError("HandleEventLeave for player ID: " + actorID + " has no PhotonPlayer!");
         }

         // having a new master before calling destroy for the leaving player is important!
         // so we elect a new masterclient and ignore the leaving player (who is still in playerlists).
         this.CheckMasterClient(actorID);


         // destroy objects & buffered messages
         if (this.mCurrentGame != null && this.mCurrentGame.autoCleanUp)
         {
             this.DestroyPlayerObjects(actorID, true);
         }

         RemovePlayer(actorID, player);

         // finally, send notification (the playerList and masterclient are now updated)
         SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerDisconnected, player);
     }