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:

     public void RegisterPhotonView(PhotonView netView)
     {
         if (!Application.isPlaying)
         {
             this.photonViewList = new Dictionary();
             return;
         }

         if (netView.viewID == 0)
         {
             // don't register views with ID 0 (not initialized). they register when a ID is assigned later on
             Debug.Log("PhotonView register is ignored, because viewID is 0. No id assigned yet to: " + netView);
             return;
         }

         if (this.photonViewList.ContainsKey(netView.viewID))
         {
             // if some other view is in the list already, we got a problem. it might be undestructible. print out error
             if (netView != photonViewList[netView.viewID])
             {
                 Debug.LogError(string.Format("PhotonView ID duplicate found: {0}. New: {1} old: {2}. Maybe one wasn't destroyed on scene load?! Check for 'DontDestroyOnLoad'. Destroying old entry, adding new.", netView.viewID, netView, photonViewList[netView.viewID]));
             }

             //this.photonViewList.Remove(netView.viewID); // TODO check if we chould Destroy the GO of this view?!
             this.RemoveInstantiatedGO(photonViewList[netView.viewID].gameObject, true);
         }

         // Debug.Log("adding view to known list: " + netView);
         this.photonViewList.Add(netView.viewID, netView);
         //Debug.LogError("view being added. " + netView); // Exit Games internal log

         if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
             Debug.Log("Registered PhotonView: " + netView.viewID);
     }