|
| 1 | +# Rivet Unity Plugin |
| 2 | + |
| 3 | +The Rivet Unity Plugin allows you to connect your game with Rivet, and easily |
| 4 | +build and ship your multiplayer games to the world in under a minute. |
| 5 | + |
| 6 | +More learning content related to Unity and Rivet can be found in the [Rivet |
| 7 | +Learning Center](https://rivet.gg/learn/unity). You can also find an example of |
| 8 | +this plugin being used in the [Rivet examples |
| 9 | +repository](https://github.com/rivet-gg/examples/tree/main/unity/tanks-fishnet). |
| 10 | + |
| 11 | +# 1.0 Table of Contents |
| 12 | + |
| 13 | +- [Rivet Unity Plugin](#rivet-unity-plugin) |
| 14 | +- [1.0 Table of Contents](#10-table-of-contents) |
| 15 | +- [2.0 Plugin Usage](#20-plugin-usage) |
| 16 | + - [2.1 Linking](#21-linking) |
| 17 | + - [2.2 Playtest Tab](#22-playtest-tab) |
| 18 | + - [2.3 Deploy Tab](#23-deploy-tab) |
| 19 | + - [2.4 Settings Tab](#24-settings-tab) |
| 20 | + - [2.5 API Usage and Reference](#25-api-usage-and-reference) |
| 21 | + |
| 22 | +# 2.0 Plugin Usage |
| 23 | + |
| 24 | +## 2.1 Linking |
| 25 | + |
| 26 | +First, you'll need to link the Rivet Unity Plugin to your project on the Rivet |
| 27 | +Hub. You can open the Rivet Unity Plugin window by going to `Window > Rivet |
| 28 | +Plugin`. |
| 29 | + |
| 30 | +At this point, if the Rivet CLI isn't installed, the plugin shows a button that |
| 31 | +handles the installation for you. |
| 32 | + |
| 33 | +After the installation, you'll be prompted to link your project with the Rivet |
| 34 | +Hub. By clicking "Sign in with Rivet", a browser window will be opened and let |
| 35 | +you select or create a project on the Rivet Hub. |
| 36 | + |
| 37 | +## 2.2 Playtest Tab |
| 38 | + |
| 39 | +The playtesting tab allows you to select how your local game and game builds |
| 40 | +will connect to Rivet servers. There are two items you can change here: |
| 41 | + |
| 42 | +- **Server**: This allows you to select if you want to connect to a locally |
| 43 | + hosted server with `This machine`, or Rivet servers with `Rivet servers`. More |
| 44 | + often, you'll likely want to use Rivet servers so that you can quickly get |
| 45 | + others testing the game with publically accessible lobbies. Local testing can |
| 46 | + allow you to run a server on your machine for better debugging purposes. |
| 47 | +- **Namespace**: This will allow you to choose which namespace you'd like to |
| 48 | + connect to. By default, the options are "Production" and "Staging", but others |
| 49 | + can be added on the Rivet Hub. |
| 50 | + |
| 51 | +## 2.3 Deploy Tab |
| 52 | + |
| 53 | +The Deploy tab allows you to build your game server and upload it to Rivet. You |
| 54 | +can choose which namespace you'd like to deploy to. By default, the options are |
| 55 | +"Production" and "Staging". |
| 56 | + |
| 57 | +Staging can be used for testing, or to playtest with others. After you upload to |
| 58 | +staging, make sure to go back to the Playtest tab and select the "Staging" |
| 59 | +namespace, and change the server to "Rivet Servers". |
| 60 | + |
| 61 | +Once you're ready to deploy to production, you can select the "Production" |
| 62 | +namespace and deploy your server there. As soon as you deploy to production, |
| 63 | +your updated server will be live for any future lobbies that are started. |
| 64 | + |
| 65 | +## 2.4 Settings Tab |
| 66 | + |
| 67 | +From the settings tab, you may unlink your game. This will bring you back to the |
| 68 | +login screen, allowing you to re-link your project if needed. |
| 69 | + |
| 70 | +## 2.5 API Usage and Reference |
| 71 | + |
| 72 | +You can find the full Rivet API reference |
| 73 | +[here](https://rivet.gg/docs/matchmaker). Items under the Matchmaker API |
| 74 | +(`lobbies`, `players`, and `regions`) are all implemented in the Unity plugin. |
| 75 | +Here's how you might use the `matchmaker/lobbies/find` endpoint: |
| 76 | + |
| 77 | +```csharp |
| 78 | +// Find lobby and connect with FishNet |
| 79 | +var rivetManager = FindObjectOfType<RivetManager>(); |
| 80 | +StartCoroutine(rivetManager.FindLobby(new FindLobbyRequest |
| 81 | +{ |
| 82 | + GameModes = new[] { gameMode }, |
| 83 | +}, res => |
| 84 | +{ |
| 85 | + // Connect to server |
| 86 | + var port = res.Ports["default"]; |
| 87 | + Debug.Log("Connecting to " + port.Hostname + ":" + port.Port); |
| 88 | + var networkManager = FindObjectOfType<NetworkManager>(); |
| 89 | + networkManager.ClientManager.StartConnection(port.Hostname, port.Port); |
| 90 | + |
| 91 | + UpdateConnectionInfo(); |
| 92 | +}, fail => { Debug.Log($"Failed to find lobby: {fail}"); })); |
| 93 | +``` |
0 commit comments