Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

rivet-gg/example-tanks-unity-fishnet

Repository files navigation

Rivet + Unity + FishNet Example

This repo has moved here!

This is a work in progress example of how to use Rivet with Unity and FishNet.

This is configured to use UDP sockets with the Tugboat transport. WebGL requires the Bayou transport, which is not included in this demo yet.

Prerequisites

  • Unity 2020.3 + Linux Dedicated Server build module
  • Rivet CLI

Getting started

Testing Locally

Rivet's APIs are all available to test locally with fake data. This is useful for testing your game without having to deploy to Rivet.

  1. Run rivet init
    • You will need to create a new game if you haven't already
    • Select unity engine type
    • Once complete, copy the token that looks like dev_staging.XXXX to your clipboard
  2. Paste this token under the API token Update token
  3. Click play in the editor and click Find Lobby
    • You should see a lobby ID of 00000000-0000-0000-0000-000000000000 in the top left. This means you're testing against your local machine.
    • If this causes an error, you may need to navigate to File > Build Settings and switch to the Windows, Mac, Linux platform Running locally

Deploying to Rivet

Deploying the server

  1. Click File > Build Settings
  2. Select Dedicated Server from the list of platforms
    • Click the Switch Platform button if it's not selected already
    • Validate Target Platform is set to Linux Build settings
  3. Click Build
  4. Create a folder named build/LinuxServer and save with the name LinuxServer. Click Save.
    • Validate that you see a file located at build/LinuxServer/LinuxServer.x86_64 Build folder
  5. Run rivet deploy -n prod to deploy to production
    • You can now see your game servers running in the Rivet dashboard. These will automatically scale up and down based on player demand.

Connecting to the server

  1. Open the Rivet Hub
  2. Navigate to Your Game > API
  3. Under Production, click Create Public Token and click the copy button Create public token
  4. Paste this token under the Rivet Token field on the Rivet API game object. This token should look like pub_prod.XXXX.
  5. Click play

Importing in to your own project

  1. Install the following Unity assets
    • FishNet
    • Json.NET
    • ParrelSync (optional, helps with testing multiple clients)
  2. Copy the following files
    • Assets/Scripts/RivetManager.cs (provides API endpoints for Rivet and manages client/server state)
    • Assets/Scripts/RivetAuthenticator.cs (integrates Rivet's authentication with FishNet,automatically created by RivetManager)
  3. Create a game object in your scene with the RivetManager component
  4. Call _rivetManager.FindLobby(...) to connect to a lobby (see RivetUI.cs for example)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages