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 OnDestroy()
     {
         if (!this.destroyedByPhotonNetworkOrQuit)
         {
             PhotonNetwork.networkingPeer.LocalCleanPhotonView(this);
         }

         if (!this.destroyedByPhotonNetworkOrQuit && !Application.isLoadingLevel)
         {
             if (this.instantiationId > 0)
             {
                 // if this viewID was not manually assigned (and we're not shutting down or loading a level), you should use PhotonNetwork.Destroy() to get rid of GOs with PhotonViews
                 Debug.LogError("OnDestroy() seems to be called without PhotonNetwork.Destroy()?! GameObject: " + this.gameObject + " Application.isLoadingLevel: " + Application.isLoadingLevel);
             }
             else
             {
                 // this seems to be a manually instantiated PV. if it's local, we could warn if the ID is not in the allocated-list
                 if (this.viewID <= 0)
                 {
                     Debug.LogWarning(string.Format("OnDestroy manually allocated PhotonView {0}. The viewID is 0. Was it ever (manually) set?", this));
                 }
                 else if (this.isMine && !PhotonNetwork.manuallyAllocatedViewIds.Contains(this.viewID))
                 {
                     Debug.LogWarning(string.Format("OnDestroy manually allocated PhotonView {0}. The viewID is local (isMine) but not in manuallyAllocatedViewIds list. Use UnAllocateViewID() after you destroyed the PV.", this));
                 }
             }
         }
     }