Unity Editor version 2022 or later.
Install Netick 2 before installing this package. https://github.com/NetickNetworking/NetickForUnity
- Open the Unity Package Manager by navigating to Window > Package Manager along the top bar.
- Click the plus icon.
- Select Add package from git URL
- Enter https://github.com/karrarrahim/UnityTransport-Netick.git
- You can then create an instance by by double clicking in the Assets folder and going to Create->Netick->Transport->UnityTransportProvider
- WebSocket (TCP)
- UDP
- Run multiple protocols in a single machine
- WebSocket & UDP
- Allowing players from WebGL and Native device to connect to the server.
If there were multiple protocols running, the selected port would be:
startPort = 7777; protocolPort = 7777 + n; Example: - UDP Starts on 7777 - WS Starts on 7778
Unity Transport is compatible with Unity Relay. You have to clone this repo and modify it by yourself to make it compatible with Relay.
- Add more enum type to the ClientNetworkProtocol and ServerNetworkProtocol with name of
Relay
- Create a public static variable to hold
Allocation
(Host) andJoinAllocation
(Client)- It's up to you where to store the static variable.
- Create a function to construct the driver for relay
private NetworkDriver ConstructDriverRelay() { RelayServerData relayData; if (Engine.IsServer) { relayData = new RelayServerData(allocation, "udp"); } else { relayData = new RelayServerData(joinAllocation, "udp"); } var settings = GetNetworkSettings(); settings.WithRelayParameters(ref relayData); // Create the Host's NetworkDriver from the NetworkSettings. var hostDriver = NetworkDriver.Create(settings); // Bind to the Relay server. return hostDriver; }
- Register the driver in
Run
method
public override void Run(RunMode mode, int port) { // .... NetworkDriver relayDriver = ConstructDriverRelay(); MultiNetworkDriver multiDriver = MultiNetworkDriver.Create(); if (Engine.IsServer) { if (ServerProtocol == ServerNetworkProtocol.All) { // ... BindAndListenDriverTo(in relayDriver, port + 2); } // ... if (ServerProtocol == ServerNetworkProtocol.Relay) BindAndListenDriverTo(in relayDriver, port); } // ... multiDriver.AddDriver(relayDriver); }
- Before Launching netick, make sure to use
CreateAllocation
andGetJoinCode
for Host and supply to theAllocation
variable. While client needs to callJoinAllocationAsync
and supply it to the public variable.