Master-Server-Unity
Master-Server-Unity copied to clipboard
Table of Contents
- Key Features
- Project structure
- master-server
- Setup database
- Unity-Server
- Create the Unity Server
- Setup server.path variable
- Unity-Client
- Contact
Key Features
- Extending EzyFox Server's room management to launch a dedicated Unity server
- One Unity-Server for all rooms/servers
(back to top)
Project structure
A brief overview of the structure of the project. We use three projects: master-server (EzyFox Server), Unity-Server and Unity-Client. It is important to know that the Unity-Servers are also clients for the master-server and we always use the Ezyfox Client SDK for communication between Unity-Client < -- > master-server and master-server< -- > Unity-Server.
(back to top)
master-server
We use an EzyFox server that acts as a master server. Its tasks are: User management, processing database requests, starting and managing a Unity server for each room. The client makes a request to the master server, which forwards the request to the Unity-Server. Once these requests have been processed by the Unity server, it is sent to the master server and from there sent back to the client(s).
Setup Database
- Install mongoDB
- Open your mongosh
- Create your Database
use master-server
- Create a new user and password and give it access to the created database
db.createUser({user: "root", pwd: "123456",roles: [{role: "readWrite", db:"master-server" }] })
- Create the following collections:
db.createCollection("user", { collation: { locale: 'en_US', strength: 2 } } )
db.user.createIndex( { username: 1 } )
db.createCollection("character", { collation: { locale: 'en_US', strength: 2 } } )
db.character.createIndex( { name: 1 } )
db.createCollection("character_location", { collation: { locale: 'en_US', strength: 2 } } )
- Use this file for the next step
Location: master-server/master-server-common/src/main/resources/master-server-common-config.properties
- Insert the following values for your database and change it to your needs.
database.mongo.uri=mongodb://root:[email protected]:27017/master-server
database.mongo.database=master-server
database.mongo.collection.naming.case=UNDERSCORE
database.mongo.collection.naming.ignored_suffix=Entity
In this example file we use:
user: root
password 123456
database: master-server
(back to top)
Unity Server
We use a single project for the Unity Servers. The server contains all server scenes that correspond to a room. When it starts, the server receives 3 parameters: username, password and room. The server then uses our Module-GameManager to start the corresponding server scene. This has the advantage that, on the one hand, we only use one project and do not have to create another server project for each server and can therefore share the code that is the same for all servers. The Module GameManager uses a persistent scene where all manager classes/GameObjects are at home. The room scene with the 3D objects such as terrain are additionally loaded.
(back to top)
Create the Unity Server
Open the Unity-Server project in Unity. Open Build Settings, File -> Build Settings. Be sure to include all server scenes in Scenes In Build, if not add them. Select as Platform Dedicated Server and chose under Target Platform your Platform Windows or Linux and Build the project.
(back to top)
Setup server path
Open the master-server project in your IDE edit the file: master-server/master-server-app-api/resources/application.properties
and add the path to your server executables from the step before where you saved it. E.g. D:/Game Builds/Unity-Server/Unity-Server.exe
(back to top)
Unity Client
Open the Unity-Client project in Unity and use the Persistent Unity Scene location Assets/Client/Scenes/Persistent
if the master-server are running you can click Play in the Unity Editor.
(back to top)
Contact
Join us on Discord
(back to top)