Skip to content

Commit 3c097e5

Browse files
committed
using NetworkSimulator preset to display the ArtificialLatencyWarning
1 parent 095c0b0 commit 3c097e5

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

Assets/Scenes/Startup.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:20e32df83c703ac495cf5641ed1d7ea6b8737a4e5a7d32a3bbb8c0651e640809
3-
size 53296
2+
oid sha256:9e8c165cd6442668e570fc8b7b0b88710f4393a8672241659b639cc07362fab6
3+
size 53896

Assets/Scripts/Utils/NetworkOverlay/NetworkLatencyWarning.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using TMPro;
3+
using Unity.Multiplayer.Tools.NetworkSimulator.Runtime;
34
using UnityEngine;
45
using Unity.Netcode;
56
using Unity.Netcode.Transports.UTP;
@@ -10,6 +11,9 @@ namespace Unity.BossRoom.Utils.Editor
1011
{
1112
public class NetworkLatencyWarning : MonoBehaviour
1213
{
14+
[SerializeField]
15+
NetworkSimulator m_NetworkSimulator;
16+
1317
TextMeshProUGUI m_LatencyText;
1418
bool m_LatencyTextCreated;
1519

@@ -25,10 +29,11 @@ void Update()
2529

2630
// adding this preprocessor directive check since UnityTransport's simulator tools only inject latency in #UNITY_EDITOR or in #DEVELOPMENT_BUILD
2731
#if UNITY_EDITOR || DEVELOPMENT_BUILD
28-
var simulatorParameters = unityTransport.DebugSimulator;
29-
m_ArtificialLatencyEnabled = simulatorParameters.PacketDelayMS > 0 ||
30-
simulatorParameters.PacketJitterMS > 0 ||
31-
simulatorParameters.PacketDropRate > 0;
32+
var currentSimulationPreset = m_NetworkSimulator.CurrentPreset;
33+
m_ArtificialLatencyEnabled = currentSimulationPreset.PacketDelayMs > 0 ||
34+
currentSimulationPreset.PacketJitterMs > 0 ||
35+
currentSimulationPreset.PacketLossInterval > 0 ||
36+
currentSimulationPreset.PacketLossPercent > 0;
3237
#else
3338
m_ArtificialLatencyEnabled = false;
3439
#endif

Assets/Scripts/Utils/Unity.BossRoom.Utils.asmdef

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"references": [
55
"Unity.TextMeshPro",
66
"Unity.Netcode.Runtime",
7+
"Unity.Multiplayer.Tools.NetworkSimulator.Runtime",
78
"Unity.Networking.Transport",
89
"Unity.Collections"
910
],

0 commit comments

Comments
 (0)