ycarowr / UnityNetworkingAPI

A Unity3D Networking API in C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unity Version Twitter

Unity Networking API

The repository contains a solution for networking in Unity, it's made in pure C# without the usage of Unity's built-in HLAPI components. Please consider that this is a project made for learning purposes, so there are limitations, bugs and a lot of room for further improvements and tests, feel free to mail me with suggestions about the architecture or anything else.

Objetives

The main goal is to have two unitypackages, client and server, whitch will be starting points for future multiplayer prototypes. And also learn the basics of networking.

Projects

Here are the code of both projects:

  1. The Client Project.
  2. The Server Project.

Here is the link to both Unity Packages.

How to use it? And Demo Apps

Inside each package there are demo applications made to help with understanding the tool.

Currently in the demo you can:

  1. Instantiate players;
  2. Move players around and jump;
  3. Send text messages Client <-> Server;

Note: all the messages are processed in the server side.

Here is an image of two demo players connected to the server:

Here are the content of the demo scenes:

Creating the Server Application

The easiest way to create a server app is described below:

  1. Download the Server UnityPackage and import it into your game server. Link here.
  2. Create a new script and open it.
  3. Add the following import on top: using UnityGameServer;
  4. Change the parent class of the script to: BaseServerApplication
  5. Drop the script into a gameObject inside the scene.
  6. Drag and drop the scriptable object that contains the server configurations. The asset is located at: UnityNetworkingAPI/UnityGameServer/Assets/UnityGameServer/ServerConfigs.asset

It should look like this picture from the DemoServerApp.cs :

  1. Press Play and you should be able to see the following start up logs, which means the server is online in your local machine:

Creating the Client Application

The client application has almost the same set of steps as the server:

  1. Download the Client UnityPackage and import it into your game client. Link here.
  2. Create a new script and open it.
  3. Add the following import on top: using UnityGameClient;
  4. Change the parent class of the script to: BaseNetworkApplication
  5. Drop the script into a gameObject inside the scene.
  6. Drag and drop the scriptable object that contains the client configurations. The asset is located at: UnityNetworkingAPI/UnityGameClient/Assets/UnityGameClient/ClientConfigs.asset

It should look like this picture from the DemoClientApp.cs :

  1. Press Play and, if the server is online in your local machine, you should be able to see the following start up logs:

After both applications are connected a player will be instantiated and you will be able to move and using the keyboard WASD and Space.

Feel free to use the tool as you need :)

References

I used Tom Weiland tutorial series as a base to start my work. Check out his videos to have complementary explanations about networking.