Unity Project Integration

What will you achieve

At the end of this tutorial you will be able to send a message from the Client to the Server and from the Server to the client

Create a new Unity Project

Open your Unity Hub and create a new Project, for the sake of simplicity in this tutorial we have chosen a 2D project, however same logic will apply to 3D.
Create a new project in Unity
Choose the 2D or 3D template

Import Scripts and Server into the project

Next from the ColyseusUnity.zip file downloaded in the previous lecture extract the Scripts folder and import it in the Unity Project at the same level where your Asset folder is.
Import Script folder from ColyseusUnity.zip
Copy and paste the Server folder into the root of the project, this can be done from file explorer. Here below I am using macOS, but same logic for Windows or Linux
Added the Server into the root of the Unity Project
We have given you a simplified version of the Server files that you need for Colyseus, the bare minimum to understand how the system works. In our opinion these files will be sufficient to integrate the game and interact with the OPArcade website and use the Colyseus server, however if you want to use the full implementation these can be downloaded directly from their Github repo​

Add Colyseus SDK to Unity

Go back to your Unity Project to install the Colyseus SDK. Open Window -> Package Manager
go to Window Package Manager
Now let's add the SDK by copy-pasting the gitURL, see the documentation for the most updated url
Select the + icon at the top left of the Package Manager and choose the Add package from git URL option. Paste the above URL and the Colyseus SDK will be installed in the project
Colyseus SDK installed

Game Objects Script

We will need to create two new separate game objects in order to manage the scripts correctly and also a special Colyseus asset. Do not worry, the process is very simple! 🦁 You have made it this far, almost there!
  • Create ServerManager and GameClient object in the scene
ServerManager and GameClient created
  • Assign the Colyseus Server Manager script to the ServerManager object
  • Assign the Game Client script to the GameClient object
  • Create a ColiseusSettings Scriptable Object in a new Settings folder
  • Assign to the ServerManager script both the GameClient and the newly created ColiseusSettings Scriptable Object

Terminal installation and check

Now that we have created all the necessary files and steps for Unity, all we need to do is to install the files locally and check that everything is running properly 🕵️‍♂️
Run npm install into the server folder from the terminal window
Run npm start in the local server, if doesnt run correctly try to trash node files and reinstall
You should now see the server logging in a message to the client and the client logging in a message to the server! All done for the basic setup! From here on you can implement more complex functions between the two
Disable secure protocol while testing locally on localhost:2567 in your Unity
​
​
​