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 void Update()
     {
         if (PhotonNetwork.networkingPeer == null)
         {
             Debug.LogError("NetworkPeer broke!");
             return;
         }

         if (PhotonNetwork.connectionStateDetailed == PeerState.PeerCreated || PhotonNetwork.connectionStateDetailed == PeerState.Disconnected || PhotonNetwork.offlineMode)
         {
             return;
         }

         // the messageQueue might be paused. in that case a thread will send acknowledgements only. nothing else to do here.
         if (!PhotonNetwork.isMessageQueueRunning)
         {
             return;
         }

         bool doDispatch = true;
         while (PhotonNetwork.isMessageQueueRunning && doDispatch)
         {
             // DispatchIncomingCommands() returns true of it found any command to dispatch (event, result or state change)
             UnityEngine.Profiling.Profiler.BeginSample("DispatchIncomingCommands");
             doDispatch = PhotonNetwork.networkingPeer.DispatchIncomingCommands();
             UnityEngine.Profiling.Profiler.EndSample();
         }

         int currentMsSinceStart = (int)(Time.realtimeSinceStartup * 1000); // avoiding Environment.TickCount, which could be negative on long-running platforms
         if (PhotonNetwork.isMessageQueueRunning && currentMsSinceStart > this.nextSendTickCountOnSerialize)
         {
             PhotonNetwork.networkingPeer.RunViewUpdate();
             this.nextSendTickCountOnSerialize = currentMsSinceStart + this.updateIntervalOnSerialize;
             this.nextSendTickCount = 0; // immediately send when synchronization code was running
         }

         currentMsSinceStart = (int)(Time.realtimeSinceStartup * 1000);
         if (currentMsSinceStart > this.nextSendTickCount)
         {
             bool doSend = true;
             while (PhotonNetwork.isMessageQueueRunning && doSend)
             {
                 // Send all outgoing commands
                 UnityEngine.Profiling.Profiler.BeginSample("SendOutgoingCommands");
                 doSend = PhotonNetwork.networkingPeer.SendOutgoingCommands();
                 UnityEngine.Profiling.Profiler.EndSample();
             }

             this.nextSendTickCount = currentMsSinceStart + this.updateInterval;
         }
     }