Unity Walkthrough Introduction


Welcome to our game integration guide! Here, you’ll learn how to integrate your game to our development environment, so that you can enjoy all that OP Arcade’s ecosystem has to offer!

Note that in this tutorial we will use the Unity game engine. The logic will be similar for any other game engine or pure JS, however we cannot assure it will be 100% compatible

We’ll start off by understanding how to switch your game’s logic to a networked oriented architecture. Next, we will get to know our main framework, Colyseus, as well as how to integrate your game with it, step by step. Finally, you will learn how to connect all of what’s been done to the OP Arcade’s Tournament API.

Switching to a Client-Server Logic

In our game programmer’s journey, we start off by building single-player games, which have a more gameplay oriented architecture and straight forward overall logic. All is done within the game’s build, and for most of the time, there is no need for any external connection.

From that very common scenario, switching your code (and mindset) to a networked, client-server architecture is no easy job! It literally requires you to think twice as much as you code since you’ll be dealing with a higher complexity level and probably a bigger tech stack than simply the one surrounding the gameplay.

But be not afraid! This guide will help you throughout this whole process while you get used to these new environments and ideas. With just a few steps you’ll be ready to embark to the next level of your skills!

The Overview

What you have in your hands is mostly an offline game. Everything runs in the game’s build and it has no connection to the outside world. That needs to change if we are to implement multiplayer and API functionalities - and also have it all done safely.

We need to break up the game into two distinct parts: a client and a server. The server is the remote part, where all the game's logic and data will be handled and cannot be modified directly by the player. The client is the local part, which will display the game's graphics, handle the player's input, send them to the server and receive it's data.

When splitting the code for this new architecture, we have to assume that anything done in the client side is "hackable", no matter the engine, framework or language you are using. So any piece of data or logic that is essential for the game's winning/scoring/ranking systems must be thoroughly examined and possibly migrated to server code.

As an example of how all of this works, let's imagine we have two classic and well known games completed, but not in a networked architecture: Tic Tac Toe and Battleship.

In Tic Tac Toe, all of our moves as well as our opponent's moves are public and visible to the both of us - we have no "secret" data being handled by the game. This may ease our worries about data protection, but even in this case, if a player has direct access to the board, he could place or remove an 'X' or an 'O' somewhere to gain an unfair advantage and win the match.

In Battleship, if any of the players have direct access to the board, it's game over! Battleship's main goal is to hit the opponent's hidden ships across the board, and so if we are allowed to peek the board for that secret information, we'll easily get an unfair victory.

In both cases, the game's data must be migrated within the server. Naturally, the logic to modify it must be there as well, leaving the player's build to be a simple "view", a graphical reflection of what's actually happening in the server.

In the image below, we can see, with a simplistic approach, how would these board games architecture would look like.

Here attached you will have a sample zip file with the files for the Unity project tutorial. The project handles the very basic of Colyseus, it logs a message to the sever and the server sends back a message to the client. This is really the bare minimum that you will need to achieve and build from there. It will be useful in order to understand how the link between the two works and will serve as boilerplate for any project you might have.

The tutorial will be based on the attached zip file, so make sure to download it locally and follow along for clarity! 👨🏼‍💻

Let's get started!

Last updated