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 LocalCleanupAnythingInstantiated(bool destroyInstantiatedGameObjects)
     {
         if (tempInstantiationData.Count > 0)
         {
             Debug.LogWarning("It seems some instantiation is not completed, as instantiation data is used. You should make sure instantiations are paused when calling this method. Cleaning now, despite this.");
         }

         // Destroy GO's (if we should)
         if (destroyInstantiatedGameObjects)
         {
             // Fill list with Instantiated objects
             HashSet instantiatedGos = new HashSet();
             foreach (PhotonView view in this.photonViewList.Values)
             {
                 if (view.isRuntimeInstantiated)
                 {
                     instantiatedGos.Add(view.gameObject); // HashSet keeps each object only once
                 }
             }

             foreach (GameObject go in instantiatedGos)
             {
                 this.RemoveInstantiatedGO(go, true);
             }
         }

         // photonViewList is cleared of anything instantiated (so scene items are left inside)
         // any other lists can be
         this.tempInstantiationData.Clear(); // should be empty but to be safe we clear (no new list needed)
         PhotonNetwork.lastUsedViewSubId = 0;
         PhotonNetwork.lastUsedViewSubIdStatic = 0;
     }