BetterTogether 0.2.0
See the version list below for details.
dotnet add package BetterTogether --version 0.2.0
NuGet\Install-Package BetterTogether -Version 0.2.0
<PackageReference Include="BetterTogether" Version="0.2.0" />
paket add BetterTogether --version 0.2.0
#r "nuget: BetterTogether, 0.2.0"
// Install BetterTogether as a Cake Addin #addin nuget:?package=BetterTogether&version=0.2.0 // Install BetterTogether as a Cake Tool #tool nuget:?package=BetterTogether&version=0.2.0
BetterTogether
BetterTogether is a simple multiplayer library targeting netstandard2.1, .NET 6, 7 and 8. It is heavily inspired by Playroom which is pretty good and available for most web frameworks/game engines. While Playroom has a Unity SDK, it only support WebGL builds of Unity (for now at least). This project however should run on any platform that supports Net Standard 2.1, .NET 6, 7 or 8.
Features
- Simple API
- Support for RPCs
- More to come (hopefully)
Usage
Setup
using BetterTogether;
// Set the max number of players to 2
BetterServer server = new BetterServer(2);
server.Start(9050);
// Connect to the server
BetterClient client = new BetterClient();
// Fired when the client is connected to the server
client.OnConnected += (id, playerList) =>
{
Console.WriteLine($"Connected as {id}");
Console.WriteLine("Players:");
foreach (var player in playerList)
{
Console.WriteLine(player);
}
};
// Fired when another player is connected
client.OnPlayerConnected += (player) =>
{
Console.WriteLine($"{player} connected");
};
client.Connect("127.0.0.1", 9050);
State
Objects need to be MemoryPackable. See MemoryPack
// SetPlayerState is used to set a player state. Only the player or the server can modify this state
client.SetPlayerState<string>("Username", "Player1");
// SetState is used to set a global state. Every player can modify this state
client.SetState<string>("foo", "bar");
// Returns the latest state of the key available on this client
client.GetState<string>("foo");
foreach(var player in client.Players)
{
Console.WriteLine(player, client.GetPlayerState<string>(player, "Username"));
}
RPCs
// Register a RPC
client.RegisterRPC("Hello", (player, args) =>
{
Console.WriteLine($"{player} says: {args[0]}");
});
// Call a RPC
client.RPC("Hello", "Hello, World!");
Unity support
Unity behaves differently, especially when it comes to threading. To use BetterTogether in Unity, you need to use some kind of dispatcher like this one inside event handlers. Here is an example using the aforementioned dispatcher
using PimDeWitte.UnityMainThreadDispatcher;
// Usual setup ignored
client.OnConnected += (id, playerList) =>
{
UnityMainThreadDispatcher.Instance().Enqueue(() =>
{
Debug.Log($"Connected as {id}");
Debug.Log("Players:");
foreach (var player in playerList)
{
Debug.Log(player);
}
});
};
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- LiteNetLib (>= 1.2.0)
- MemoryPack (>= 1.21.1)
-
net6.0
- LiteNetLib (>= 1.2.0)
- MemoryPack (>= 1.21.1)
-
net7.0
- LiteNetLib (>= 1.2.0)
- MemoryPack (>= 1.21.1)
-
net8.0
- LiteNetLib (>= 1.2.0)
- MemoryPack (>= 1.21.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.10.0 | 107 | 7/7/2024 |
0.9.1 | 89 | 6/22/2024 |
0.9.0 | 92 | 6/22/2024 |
0.8.2 | 91 | 6/22/2024 |
0.8.1 | 84 | 6/21/2024 |
0.8.0 | 93 | 6/21/2024 |
0.7.0 | 94 | 6/21/2024 |
0.6.0 | 100 | 6/20/2024 |
0.5.2 | 95 | 6/20/2024 |
0.5.1 | 84 | 6/20/2024 |
0.5.0 | 80 | 6/20/2024 |
0.4.1 | 98 | 6/20/2024 |
0.4.0 | 91 | 6/19/2024 |
0.3.0 | 102 | 6/18/2024 |
0.2.0 | 88 | 6/18/2024 |