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 bool Connect(string address, ConnectionProtocol protocol, string appId, string appVersion, string userId, AuthenticationValues authValues)
         {
             if (!this.HasPeer)
             {
                 this.chatPeer = new ChatPeer(this, protocol);
             }
             else
             {
                 this.Disconnect();
                 if (this.chatPeer.UsedProtocol != protocol)
                 {
                     this.chatPeer = new ChatPeer(this, protocol);
                 }
             }

#if UNITY
#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)
                 UnityEngine.Debug.Log("Using class SocketUdpNativeDynamic");
                 this.chatPeer.SocketImplementation = typeof(SocketUdpNativeDynamic);
#elif !UNITY_EDITOR && UNITY_IPHONE
                 UnityEngine.Debug.Log("Using class SocketUdpNativeStatic");
                 this.chatPeer.SocketImplementation = typeof(SocketUdpNativeStatic);
#elif !UNITY_EDITOR && (UNITY_WINRT)
                 // this automatically uses a separate assembly-file with Win8-style Socket usage (not possible in Editor)
#else
                 Type udpSocket = Type.GetType("ExitGames.Client.Photon.SocketUdp, Assembly-CSharp");
                 this.chatPeer.SocketImplementation = udpSocket;
                 if (udpSocket == null)
                 {
                     UnityEngine.Debug.Log("ChatClient could not find a suitable C# socket class. The Photon3Unity3D.dll only supports native socket plugins.");
                 }
#endif
                 if (this.chatPeer.SocketImplementation == null)
                 {
                     UnityEngine.Debug.Log("No socket implementation set for 'NoSocket' assembly. Please contact Exit Games.");
                 }
             }
#pragma warning restore 0162
#endif

             this.chatPeer.TimePingInterval = 3000;
             this.DisconnectedCause = ChatDisconnectCause.None;

             this.CustomAuthenticationValues = authValues;
             this.UserId = userId;
             this.AppId = appId;
             this.AppVersion = appVersion;
             this.didAuthenticate = false;
             this.msDeltaForServiceCalls = 100;


             // clean all channels
             this.PublicChannels.Clear();
             this.PrivateChannels.Clear();

             if (!address.Contains(":"))
             {
                 int port = 0;
                 ProtocolToNameServerPort.TryGetValue(protocol, out port);
                 address = string.Format("{0}:{1}", address, port);
             }

             bool isConnecting = this.chatPeer.Connect(address, "NameServer");
             if (isConnecting)
             {
                 this.State = ChatState.ConnectingToNameServer;
             }
             return isConnecting;
         }