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:

     void OnGUI()
     {
         if (PhotonNetwork.connected)
         {
             GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
             return;
         }


         GUILayout.BeginArea(GuiRect);
         switch (guiState)
         {
             case GuiState.AuthFailed:
                 GUILayout.Label("Authentication Failed");

                 GUILayout.Space(10);

                 GUILayout.Label("Error message:\n'" + this.authDebugMessage + "'");

                 GUILayout.Space(10);

                 GUILayout.Label("For this demo set the Authentication URL in the Dashboard to:\nhttp://photon.webscript.io/auth-demo-equals");
                 GUILayout.Label("That authentication-service has no user-database. It confirms any user if 'name equals password'.");
                 GUILayout.Label("The error message comes from that service and can be customized.");

                 GUILayout.Space(10);

                 GUILayout.BeginHorizontal();
                 if (GUILayout.Button("Back"))
                 {
                     SetStateAuthInput();
                 }
                 if (GUILayout.Button("Help"))
                 {
                     SetStateAuthHelp();
                 }
                 GUILayout.EndHorizontal();
                 break;

             case GuiState.AuthHelp:

                 GUILayout.Label("By default, any player can connect to Photon.\n'Custom Authentication' can be enabled to reject players without valid user-account.");

                 GUILayout.Label("The actual authentication must be done by a web-service which you host and customize. Example sourcecode for these services is available on the docs page.");

                 GUILayout.Label("For this demo set the Authentication URL in the Dashboard to:\nhttp://photon.webscript.io/auth-demo-equals");
                 GUILayout.Label("That authentication-service has no user-database. It confirms any user if 'name equals password'.");

                 GUILayout.Space(10);
                 if (GUILayout.Button("Configure Authentication (Dashboard)"))
                 {
                     Application.OpenURL("https://cloud.exitgames.com/dashboard");
                 }
                 if (GUILayout.Button("Authentication Docs"))
                 {
                     Application.OpenURL("https://doc.exitgames.com/en/pun/current/tutorials/pun-and-facebook-custom-authentication");
                 }


                 GUILayout.Space(10);
                 if (GUILayout.Button("Back to input"))
                 {
                     SetStateAuthInput();
                 }
                 break;

             case GuiState.AuthInput:

                 GUILayout.Label("Authenticate yourself");

                 GUILayout.BeginHorizontal();
                 this.authName = GUILayout.TextField(this.authName, GUILayout.Width(Screen.width/4 - 5));
                 GUILayout.FlexibleSpace();
                 this.authToken = GUILayout.TextField(this.authToken, GUILayout.Width(Screen.width/4 - 5));
                 GUILayout.EndHorizontal();


                 if (GUILayout.Button("Authenticate"))
                 {
                     PhotonNetwork.AuthValues = new AuthenticationValues();
                     PhotonNetwork.AuthValues.SetAuthParameters(this.authName, this.authToken);
                     PhotonNetwork.ConnectUsingSettings("1.0");
                 }

                 GUILayout.Space(10);

                 if (GUILayout.Button("Help", GUILayout.Width(100)))
                 {
                     SetStateAuthHelp();
                 }

                 break;
         }

         GUILayout.EndArea();
     }