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:

     /// - Invalid AppId (calls: OnFailedToConnectToPhoton(). check exact AppId value)
     /// - Network issues (calls: OnFailedToConnectToPhoton())
     /// - Invalid region (calls: OnConnectionFail() with DisconnectCause.InvalidRegion)
     /// - Subscription CCU limit reached (calls: OnConnectionFail() with DisconnectCause.MaxCcuReached. also calls: OnPhotonMaxCccuReached())
     public static bool ConnectUsingSettings(string gameVersion)
     {
         if (PhotonServerSettings == null)
         {
             Debug.LogError("Can't connect: Loading settings failed. ServerSettings asset must be in any 'Resources' folder as: " + serverSettingsAssetFile);
             return false;
         }

         SwitchToProtocol(PhotonServerSettings.Protocol);
         networkingPeer.SetApp(PhotonServerSettings.AppID, gameVersion);

         if (PhotonServerSettings.HostType == ServerSettings.HostingOption.OfflineMode)
         {
             offlineMode = true;
             return true;
         }

         if (offlineMode)
         {
             // someone can set offlineMode in code and then call ConnectUsingSettings() with non-offline settings. Warning for that case:
             Debug.LogWarning("ConnectUsingSettings() disabled the offline mode. No longer offline.");
         }

         offlineMode = false; // Cleanup offline mode
         isMessageQueueRunning = true;
         networkingPeer.IsInitialConnect = true;

         if (PhotonServerSettings.HostType == ServerSettings.HostingOption.SelfHosted)
         {
             networkingPeer.IsUsingNameServer = false;
             networkingPeer.MasterServerAddress = (PhotonServerSettings.ServerPort == 0) ? PhotonServerSettings.ServerAddress : PhotonServerSettings.ServerAddress + ":" + PhotonServerSettings.ServerPort;

             return networkingPeer.Connect(networkingPeer.MasterServerAddress, ServerConnection.MasterServer);
         }

         if (PhotonServerSettings.HostType == ServerSettings.HostingOption.BestRegion)
         {
             return ConnectToBestCloudServer(gameVersion);
         }

         return networkingPeer.ConnectToRegionMaster(PhotonServerSettings.PreferredRegion);
     }