- Extending EzyFox Server's room management to launch a dedicated Unity server
- One Unity-Server for all rooms/servers
- Area of interest System on the Unity-Server
- Capability to spawn or despawn entities based on range
- Each entity has a NearbyPlayer list and sends position updates only to players in this list
- Entity-based System
- An entity is the base and can be a player, effect, or building (currently, only Player is implemented)
- Each entity automatically adds the NetworkTransform component, is added to the client’s entity list, and receives position updates or spawn/despawn events based on range
Clone the repository:
git clone git@github.com:Assambra/Master-Server-Unity.git
Download and extract the file: ezyfox-server-csharp-client-1.1.6-unity.zip.
Perform the following steps for both Unity projects: Unity-Client and Unity-Server:
- Insert the extracted folder
ezyfox-server-csharp-client-1.1.6-unity
into the root folder/Assets
of your opened Unity project. - Open the Unity Editor and navigate to the folder
Assets/ezyfox-server-csharp-client-1.1.6-unity
. - Right-click inside the folder -> Create -> Assembly Definition, and rename it to
com.tvd12.ezyfoxserver.client
.
In the Unity Editor:
- Navigate to
Assets/Unity-Server/Scripts/Assambra.Server
. - In the Inspector, locate the Assembly Definition Reference section.
- Remove the missing reference starting with
GUID:
(if present). - Add a new reference by clicking the plus sign (+) and select the earlier created
com.tvd12.ezyfoxserver.client
assembly definition. - Click Apply.
Repeat the same steps for the Unity-Client project:
- Navigate to
Assets/Unity-Client/Scripts/Assambra.Client
. - Follow the same process for updating the Assembly Definition Reference.
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.
We use an EzyFox server that acts as a master server. Its tasks are user management, processing database requests, and 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, they are sent to the master server and from there sent back to the client(s).
- 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 them to your needs:
database.mongo.uri=mongodb://root:123456@127.0.0.1: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
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 three 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 located. The room scene with the 3D objects such as terrain are additionally loaded.
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 choose under Target Platform your platform, Windows or Linux, and build the project.
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 previous step where you saved them. E.g., D:/Game Builds/Unity-Server/Unity-Server.exe
.
Open the Unity-Client project in Unity and use the Persistent Unity Scene location Assets/Client/Scenes/Persistent
. If the master-server is running, you can click Play in the Unity Editor.
Join us on Discord