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 NetworkingPeer(IPhotonPeerListener listener, string playername, ConnectionProtocol connectionProtocol) : base(listener, connectionProtocol)
     {
         #if !UNITY_EDITOR && (UNITY_WINRT)
         // this automatically uses a separate assembly-file with Win8-style Socket usage (not possible in Editor)
         Debug.LogWarning("Using PingWindowsStore");
         PhotonHandler.PingImplementation = typeof(PingWindowsStore); // but for ping, we have to set the implementation explicitly to Win 8 Store/Phone
         #endif

         #pragma warning disable 0162 // the library variant defines if we should use PUN's SocketUdp variant (at all)
         if (PhotonPeer.NoSocket)
         {
             #if !UNITY_EDITOR && (UNITY_PS3 || UNITY_ANDROID)
             Debug.Log("Using class SocketUdpNativeDynamic");
             this.SocketImplementation = typeof(SocketUdpNativeDynamic);
             PhotonHandler.PingImplementation = typeof(PingNativeDynamic);
             #elif !UNITY_EDITOR && UNITY_IPHONE
             Debug.Log("Using class SocketUdpNativeStatic");
             this.SocketImplementation = typeof(SocketUdpNativeStatic);
             PhotonHandler.PingImplementation = typeof(PingNativeStatic);
             #elif !UNITY_EDITOR && (UNITY_WINRT)
             // this automatically uses a separate assembly-file with Win8-style Socket usage (not possible in Editor)
             #else
             this.SocketImplementation = typeof (SocketUdp);
             PhotonHandler.PingImplementation = typeof(PingMonoEditor);
             #endif

             if (this.SocketImplementation == null)
             {
                 Debug.Log("No socket implementation set for 'NoSocket' assembly. Please contact Exit Games.");
             }
         }
         #pragma warning restore 0162

         if (PhotonHandler.PingImplementation == null)
         {
             PhotonHandler.PingImplementation = typeof(PingMono);
         }

         this.Listener = this;
         this.lobby = TypedLobby.Default;
         this.LimitOfUnreliableCommands = 40;

         // don't set the field directly! the listener is passed on to other classes, which get updated by the property set method
         this.externalListener = listener;
         this.PlayerName = playername;
         this.mLocalActor = new PhotonPlayer(true, -1, this.playername);
         this.AddNewPlayer(this.mLocalActor.ID, this.mLocalActor);

         // RPC shortcut lookup creation (from list of RPCs, which is updated by Editor scripts)
         rpcShortcuts = new Dictionary(PhotonNetwork.PhotonServerSettings.RpcList.Count);
         for (int index = 0; index < PhotonNetwork.PhotonServerSettings.RpcList.Count; index++)
         {
             var name = PhotonNetwork.PhotonServerSettings.RpcList[index];
             rpcShortcuts[name] = index;
         }

         this.State = global::PeerState.PeerCreated;
     }