Skip to content

Commit 78f118c

Browse files
authored
feature: transport picker improvements (#200)
1 parent 339b1db commit 78f118c

File tree

80 files changed

+55
-9057
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+55
-9057
lines changed

ARCHITECTURE.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ For an in-depth overview of the project's architecture please check out our [ARC
5050
- Once path-plan is finished, server representation of entity starts updating its NetworkedTransform at 30fps. Graphics is on a separate GO and is connected to the networked GO via a spring, to smooth out small corrections.
5151
- Graphics GO never passes the simulation GO; if it catches up to the sim due to a network delay, the user will see a hitch.
5252

53+
### Transports
54+
55+
Boss Room provides players with two ways to connect to a server.
56+
57+
- IP based: The clients connect directy to a host via IP address. This will only work if both are in the same local are network or if the host forwards ports.
58+
- Relay Based: The clients and the host connect to a relay server with a room key and run all traffic over this relay server.
59+
60+
To allow for both of these options to be chosen at runtime we created `TransportPicker`. `Transport` picker allows to chose a ip based and a relay based transport and will hook up the game UI to use those transports. The transport field in the `NetworkManager` will be ignored. Currently we support the following transports:
61+
- **UNet(IP):** UNet is the default MLAPI transport and the default IP transport for Boss Room.
62+
- **LiteNetLib(IP):** We use LiteNetLib in Boss Room because it has a built in way to simulate latency which is useful for spotting networking issues early during development.
63+
- **Photon Realtime (Relay):** Photon Realtime is a relay transport using the [Photon Realtime Service](https://www.photonengine.com/Realtime).
64+
65+
To add new transport in the project parts of `GameNetPortal` and `ClientGameNetPortal` (transport switches) need to be extended.
66+
5367
### Navigation System
5468

5569
#### Building a navigation mesh

Assets/BossRoom/Prefabs/NetworkingManager.prefab

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ MonoBehaviour:
4646
m_NickName:
4747
m_RoomName:
4848
m_MaxPlayers: 16
49-
m_ChannelIdCodesStartRange: 0
49+
m_ChannelIdCodesStartRange: 130
5050
m_AttachSupportLogger: 0
5151
m_BatchMode: 1
5252
m_SendQueueBatchSize: 4096
5353
m_BatchedTransportEventCode: 129
54-
m_KickEventCode: 130
5554
--- !u!1 &3591499506183471245
5655
GameObject:
5756
m_ObjectHideFlags: 0
@@ -68,7 +67,7 @@ GameObject:
6867
m_Icon: {fileID: 0}
6968
m_NavMeshLayer: 0
7069
m_StaticEditorFlags: 0
71-
m_IsActive: 0
70+
m_IsActive: 1
7271
--- !u!4 &5355783542964773244
7372
Transform:
7473
m_ObjectHideFlags: 0
@@ -115,8 +114,8 @@ GameObject:
115114
serializedVersion: 6
116115
m_Component:
117116
- component: {fileID: 5436007408952557925}
118-
- component: {fileID: 5436007408952557924}
119117
- component: {fileID: 1359040526}
118+
- component: {fileID: 5436007408952557924}
120119
m_Layer: 0
121120
m_Name: NetworkingManager
122121
m_TagString: Untagged
@@ -141,6 +140,20 @@ Transform:
141140
m_Father: {fileID: 0}
142141
m_RootOrder: 0
143142
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
143+
--- !u!114 &1359040526
144+
MonoBehaviour:
145+
m_ObjectHideFlags: 0
146+
m_CorrespondingSourceObject: {fileID: 0}
147+
m_PrefabInstance: {fileID: 0}
148+
m_PrefabAsset: {fileID: 0}
149+
m_GameObject: {fileID: 5436007408952557947}
150+
m_Enabled: 1
151+
m_EditorHideFlags: 0
152+
m_Script: {fileID: 11500000, guid: 0c0e18361257a9f409d6064bac74e732, type: 3}
153+
m_Name:
154+
m_EditorClassIdentifier:
155+
m_IpHostTransport: {fileID: 7898291372908163337}
156+
m_RelayTransport: {fileID: 409269882}
144157
--- !u!114 &5436007408952557924
145158
MonoBehaviour:
146159
m_ObjectHideFlags: 0
@@ -225,20 +238,6 @@ MonoBehaviour:
225238
type: {class: NullableBoolSerializable, ns: MLAPI.Configuration, asm: Unity.Multiplayer.MLAPI.Runtime}
226239
data:
227240
Value: 1897319656204293034
228-
--- !u!114 &1359040526
229-
MonoBehaviour:
230-
m_ObjectHideFlags: 0
231-
m_CorrespondingSourceObject: {fileID: 0}
232-
m_PrefabInstance: {fileID: 0}
233-
m_PrefabAsset: {fileID: 0}
234-
m_GameObject: {fileID: 5436007408952557947}
235-
m_Enabled: 1
236-
m_EditorHideFlags: 0
237-
m_Script: {fileID: 11500000, guid: 0c0e18361257a9f409d6064bac74e732, type: 3}
238-
m_Name:
239-
m_EditorClassIdentifier:
240-
m_IpHostTransport: {fileID: 7898291372908163337}
241-
m_RelayTransport: {fileID: 409269882}
242241
--- !u!1 &6889060209805043266
243242
GameObject:
244243
m_ObjectHideFlags: 0

Assets/BossRoom/Scripts/Client/BossRoom.Client.asmdef

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"Unity.Multiplayer.MLAPI.Runtime",
66
"BossRoom.Shared",
77
"Cinemachine",
8-
"LiteNEt MLAPI Transport",
9-
"Photon Realtime MLAPI Transport"
8+
"Photon Realtime MLAPI Transport",
9+
"LiteNetLib MLAPI Transport"
1010
],
1111
"includePlatforms": [],
1212
"excludePlatforms": [],

Assets/BossRoom/Scripts/Client/Net/ClientGameNetPortal.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEngine.SceneManagement;
44
using MLAPI;
55
using MLAPI.Transports;
6+
using MLAPI.Transports.LiteNetLib;
67
using MLAPI.Transports.PhotonRealtime;
78
using MLAPI.Transports.UNET;
89

@@ -95,9 +96,11 @@ public static void StartClient(GameNetPortal portal, string ipaddress, int port)
9596
{
9697
//DMW_NOTE: non-portable. We need to be updated when moving to UTP transport.
9798
var chosenTransport = NetworkManager.Singleton.gameObject.GetComponent<TransportPicker>().IpHostTransport;
99+
NetworkManager.Singleton.NetworkConfig.NetworkTransport = chosenTransport;
100+
98101
switch (chosenTransport)
99102
{
100-
case LiteNetLibTransport.LiteNetLibTransport liteNetLibTransport:
103+
case LiteNetLibTransport liteNetLibTransport:
101104
liteNetLibTransport.Address = ipaddress;
102105
liteNetLibTransport.Port = (ushort)port;
103106
break;

Assets/BossRoom/Scripts/Shared/BossRoom.Shared.asmdef

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"rootNamespace": "",
44
"references": [
55
"Unity.Multiplayer.MLAPI.Runtime",
6-
"LiteNEt MLAPI Transport",
7-
"Photon Realtime MLAPI Transport"
6+
"Photon Realtime MLAPI Transport",
7+
"LiteNetLib MLAPI Transport"
88
],
99
"includePlatforms": [],
1010
"excludePlatforms": [],

Assets/BossRoom/Scripts/Shared/Game/UI/Editor/NetworkLatencyWarning.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEngine.UI;
44
using MLAPI;
55
using MLAPI.Transports;
6+
using MLAPI.Transports.LiteNetLib;
67
using MLAPI.Transports.PhotonRealtime;
78
using UnityEngine.Assertions;
89

@@ -27,7 +28,7 @@ void Update()
2728
{
2829
// adding this preprocessor directive check since LiteNetLib only injects latency in #DEBUG
2930
#if DEBUG
30-
case LiteNetLibTransport.LiteNetLibTransport liteNetLibTransport:
31+
case LiteNetLibTransport liteNetLibTransport:
3132
m_ArtificialLatencyEnabled = liteNetLibTransport.SimulatePacketLossChance > 0 ||
3233
liteNetLibTransport.SimulateMinLatency > 0 ||
3334
liteNetLibTransport.SimulateMaxLatency > 0;

Assets/BossRoom/Scripts/Shared/Net/GameNetPortal.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
2-
using System.Net.Sockets;
32
using MLAPI.Serialization.Pooled;
43
using MLAPI.Transports;
54
using MLAPI;
5+
using MLAPI.Transports.LiteNetLib;
66
using MLAPI.Transports.PhotonRealtime;
77
using UnityEngine;
88

@@ -167,7 +167,7 @@ public void StartHost(string ipaddress, int port)
167167
//DMW_NOTE: non-portable. We need to be updated when moving to UTP transport.
168168
switch (chosenTransport)
169169
{
170-
case LiteNetLibTransport.LiteNetLibTransport liteNetLibTransport:
170+
case LiteNetLibTransport liteNetLibTransport:
171171
liteNetLibTransport.Address = ipaddress;
172172
liteNetLibTransport.Port = (ushort)port;
173173
break;

Assets/BossRoom/Scripts/Shared/TransportPicker.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
2-
using System.Collections;
3-
using System.Collections.Generic;
4-
using BossRoom;
5-
using MLAPI;
62
using MLAPI.Transports;
3+
using MLAPI.Transports.LiteNetLib;
74
using MLAPI.Transports.PhotonRealtime;
85
using MLAPI.Transports.UNET;
96
using UnityEngine;
@@ -32,7 +29,7 @@ public class TransportPicker : MonoBehaviour
3229

3330
void OnValidate()
3431
{
35-
Assert.IsTrue(m_IpHostTransport == null || (m_IpHostTransport as UNetTransport || m_IpHostTransport as LiteNetLibTransport.LiteNetLibTransport),
32+
Assert.IsTrue(m_IpHostTransport == null || (m_IpHostTransport as UNetTransport || m_IpHostTransport as LiteNetLibTransport),
3633
"IpHost transport must be either Unet or LiteNetLib transport.");
3734

3835
Assert.IsTrue(m_RelayTransport == null || (m_RelayTransport as PhotonRealtimeTransport), "" +

Packages/com.unity.multiplayer.transport.litenet/CHANGELOG.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

Packages/com.unity.multiplayer.transport.litenet/CHANGELOG.md.meta

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)