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 OnSerializeRead(Hashtable data, PhotonPlayer sender, int networkTime, short correctPrefix)
     {
         // read view ID from key (byte)0: a int-array (PUN 1.17++)
         int viewID = (int)data[(byte)0];


         PhotonView view = this.GetPhotonView(viewID);
         if (view == null)
         {
             Debug.LogWarning("Received OnSerialization for view ID " + viewID + ". We have no such PhotonView! Ignored this if you're leaving a room. State: " + this.State);
             return;
         }

         if (view.prefix > 0 && correctPrefix != view.prefix)
         {
             Debug.LogError("Received OnSerialization for view ID " + viewID + " with prefix " + correctPrefix + ". Our prefix is " + view.prefix);
             return;
         }

         // SetReceiving filtering
         if (view.group != 0 && !this.allowedReceivingGroups.Contains(view.group))
         {
             return; // Ignore group
         }


         if (view.synchronization == ViewSynchronization.ReliableDeltaCompressed)
         {
             if (!this.DeltaCompressionRead(view, data))
             {
                 // Skip this packet as we haven't got received complete-copy of this view yet.
                 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
                     Debug.Log("Skipping packet for " + view.name + " [" + view.viewID + "] as we haven't received a full packet for delta compression yet. This is OK if it happens for the first few frames after joining a game.");
                 return;
             }

             // store last received for delta-compression usage
             view.lastOnSerializeDataReceived = data[(byte)1] as object[];
         }

         if (sender.ID != view.ownerId)
         {
             if (!view.isSceneView || !sender.isMasterClient)
             {
                 // obviously the owner changed and we didn't yet notice.
                 Debug.Log("Adjusting owner to sender of updates. From: " + view.ownerId + " to: " + sender.ID);
                 view.ownerId = sender.ID;
             }
         }

         object[] contents = data[(byte)1] as object[];
         PhotonStream pStream = new PhotonStream(false, contents);
         PhotonMessageInfo info = new PhotonMessageInfo(sender, networkTime, view);

         view.DeserializeView( pStream, info );
     }