๐Ÿ““

GameServerAutoSetup

public class GameServerAutoSetup : MonoBehaviour
{
    public static bool autoGameServer = false;
    public static string autoGameServerName = "game";
    public static int autoGameServerPort = 7000;
    public static string autoGameServerMasterServerIP = "127.0.0.1";
    public static int autoGameServerMasterServerPort = 7000;
//...

This class is used to determine if when the game runs if this instance of the game should be a dedicated server. If it finds a gameDetails.txt in its folder and it has success reading it, then it will jump through the menu so it is hosting a game for clients to join without the need for any human input. Very handy for if you want new Server instances to be created whenever they are needed or if you wish to setup and leave a server running somewhere, you can easily.

Methods

void Start()

On this Unity start method, if it can read a file called gameDetails.txt then it will launch the game into server mode. The gameDetails.txt should have the following details on separated lines:

For example this might look like:

Awesome Sydney Server

7777

127.0.0.1

7000

After it reads a file like this it currently changes to Unity Scene called โ€œJoinโ€, but you are welcome to change this. The Join scene will do the actual setting this game up as a server, connecting to Master Server to list for clients to join and then eventually jumping to the first game map

NOTE: You may want to tweak this class, perhaps you want the gameDetails.txt to also house the game mode, maps and any other bits of info too. For cleanliness I have this class attached to a Unity GameObject in a Separate scene and only include it into the builds I want for dedicated servers, but you could put this into the main menu if you needed to.