Skip to content

Commit 77968e1

Browse files
committed
Merge branch 'develop' into pdeschain/folder-assembly-refactor
2 parents f717684 + e05bfdf commit 77968e1

File tree

14 files changed

+206
-55
lines changed

14 files changed

+206
-55
lines changed

Assets/BossRoom/Prefabs/Debug Overlay Canvas.prefab

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ RectTransform:
2929
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
3030
m_LocalPosition: {x: 0, y: 0, z: 0}
3131
m_LocalScale: {x: 0, y: 0, z: 0}
32+
m_ConstrainProportionsScale: 0
3233
m_Children:
3334
- {fileID: 2084502874807427418}
3435
m_Father: {fileID: 0}
@@ -72,10 +73,10 @@ MonoBehaviour:
7273
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
7374
m_Name:
7475
m_EditorClassIdentifier:
75-
m_UiScaleMode: 0
76+
m_UiScaleMode: 1
7677
m_ReferencePixelsPerUnit: 100
7778
m_ScaleFactor: 1
78-
m_ReferenceResolution: {x: 800, y: 600}
79+
m_ReferenceResolution: {x: 1920, y: 1080}
7980
m_ScreenMatchMode: 0
8081
m_MatchWidthOrHeight: 0
8182
m_PhysicalUnit: 3
@@ -127,14 +128,15 @@ RectTransform:
127128
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
128129
m_LocalPosition: {x: 0, y: 0, z: 0}
129130
m_LocalScale: {x: 1, y: 1, z: 1}
131+
m_ConstrainProportionsScale: 0
130132
m_Children: []
131133
m_Father: {fileID: 5075973321638144936}
132134
m_RootOrder: 0
133135
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
134136
m_AnchorMin: {x: 0, y: 0}
135137
m_AnchorMax: {x: 0, y: 0}
136138
m_AnchoredPosition: {x: 40, y: 40}
137-
m_SizeDelta: {x: 240, y: 400}
139+
m_SizeDelta: {x: 400, y: 400}
138140
m_Pivot: {x: 0, y: 0}
139141
--- !u!114 &3464894946384537378
140142
MonoBehaviour:

Assets/BossRoom/Scenes/BossRoom.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:cd0792f12a7e463be8d0d45b8ff8f1c2c53933b1d93c5cc17e70ee045756c7a4
3-
size 503413
2+
oid sha256:3de6367e1590522862f4e215fee25c7625e74596ab09067345a67c895080139c
3+
size 508257

Assets/BossRoom/Scripts/Gameplay/UI/Lobby/LobbyJoiningUI.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ void InjectDependenciesAndInitialize(
5353
m_LobbyUIMediator = lobbyUIMediator;
5454
m_UpdateRunner = updateRunner;
5555

56-
m_UpdateRunner.Subscribe(PeriodicRefresh, 10f);
57-
5856
m_Subscriptions = localLobbiesRefreshedSub.Subscribe(UpdateUI);
5957
}
6058

@@ -142,12 +140,14 @@ public void Show()
142140
m_CanvasGroup.blocksRaycasts = true;
143141
m_JoinCodeField.text = "";
144142
OnRefresh();
143+
m_UpdateRunner.Subscribe(PeriodicRefresh, 10f);
145144
}
146145

147146
public void Hide()
148147
{
149148
m_CanvasGroup.alpha = 0f;
150149
m_CanvasGroup.blocksRaycasts = false;
150+
m_UpdateRunner.Unsubscribe(PeriodicRefresh);
151151
}
152152
}
153153
}

Assets/BossRoom/Scripts/Infrastructure/NetworkOverlay/NetworkLatencyWarning.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using TMPro;
23
using UnityEngine;
34
using UnityEngine.UI;
45
using Unity.Netcode;
@@ -10,7 +11,7 @@ namespace Unity.Multiplayer.Samples.BossRoom.Editor
1011
{
1112
public class NetworkLatencyWarning : MonoBehaviour
1213
{
13-
Text m_LatencyText;
14+
TextMeshProUGUI m_LatencyText;
1415
bool m_LatencyTextCreated;
1516

1617
Color m_TextColor = Color.red;
@@ -66,19 +67,7 @@ void CreateLatencyText()
6667
Assert.IsNotNull(NetworkOverlay.Instance,
6768
"No NetworkOverlay object part of scene. Add NetworkOverlay prefab to bootstrap scene!");
6869

69-
var statUI = new GameObject("UI Latency Warning Text");
70-
71-
m_LatencyText = statUI.AddComponent<Text>();
72-
m_LatencyText.font = Font.CreateDynamicFontFromOSFont("Arial", 24);
73-
m_LatencyText.horizontalOverflow = HorizontalWrapMode.Overflow;
74-
m_LatencyText.alignment = TextAnchor.MiddleLeft;
75-
m_LatencyText.raycastTarget = false;
76-
m_LatencyText.resizeTextForBestFit = true;
77-
78-
m_LatencyText.text = "Network Latency Enabled";
79-
80-
var statUIRectTransform = statUI.GetComponent<RectTransform>();
81-
NetworkOverlay.Instance.AddToUI(statUIRectTransform);
70+
NetworkOverlay.Instance.AddTextToUI("UI Latency Warning Text", "Network Latency Enabled", out m_LatencyText);
8271
}
8372
}
8473
}

Assets/BossRoom/Scripts/Infrastructure/NetworkOverlay/NetworkOverlay.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using TMPro;
12
using UnityEngine;
23
using UnityEngine.UI;
34

@@ -18,6 +19,21 @@ void Awake()
1819
DontDestroyOnLoad(this);
1920
}
2021

22+
public void AddTextToUI(string gameObjectName, string defaultText, out TextMeshProUGUI textComponent)
23+
{
24+
var rootGO = new GameObject(gameObjectName);
25+
textComponent = rootGO.AddComponent<TextMeshProUGUI>();
26+
textComponent.fontSize = 28;
27+
textComponent.text = defaultText;
28+
textComponent.horizontalAlignment = HorizontalAlignmentOptions.Left;
29+
textComponent.verticalAlignment = VerticalAlignmentOptions.Middle;
30+
textComponent.raycastTarget = false;
31+
textComponent.autoSizeTextContainer = true;
32+
33+
var rectTransform = rootGO.GetComponent<RectTransform>();
34+
AddToUI(rectTransform);
35+
}
36+
2137
public void AddToUI(RectTransform displayTransform)
2238
{
2339
if (m_VerticalLayoutTransform == null)
@@ -28,6 +44,7 @@ public void AddToUI(RectTransform displayTransform)
2844
displayTransform.sizeDelta = new Vector2(100f, 24f);
2945
displayTransform.SetParent(m_VerticalLayoutTransform);
3046
displayTransform.SetAsFirstSibling();
47+
displayTransform.localScale = Vector3.one;
3148
}
3249

3350
void CreateDebugCanvas()

Assets/BossRoom/Scripts/Infrastructure/NetworkStats.cs

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ public ExponentialMovingAverageCalculator(float average)
4242
const float k_PingIntervalSeconds = 0.1f;
4343
const float k_MaxWindowSize = k_MaxWindowSizeSeconds / k_PingIntervalSeconds;
4444

45+
// Some games are less sensitive to latency than others. For fast-paced games, latency above 100ms becomes a challenge for players while for others 500ms is fine. It's up to you to establish those thresholds.
46+
const float k_StrugglingNetworkConditionsRTTThreshold = 130;
47+
const float k_BadNetworkConditionsRTTThreshold = 200;
48+
4549
ExponentialMovingAverageCalculator m_BossRoomRTT = new ExponentialMovingAverageCalculator(0);
4650
ExponentialMovingAverageCalculator m_UtpRTT = new ExponentialMovingAverageCalculator(0);
4751

4852
float m_LastPingTime;
4953
TextMeshProUGUI m_TextStat;
5054
TextMeshProUGUI m_TextHostType;
55+
TextMeshProUGUI m_TextBadNetworkConditions;
5156

5257
// When receiving pong client RPCs, we need to know when the initiating ping sent it so we can calculate its individual RTT
5358
int m_CurrentRTTPingId;
@@ -86,23 +91,9 @@ void CreateNetworkStatsText()
8691
"No NetworkOverlay object part of scene. Add NetworkOverlay prefab to bootstrap scene!");
8792

8893
string hostType = IsHost ? "Host" : IsClient ? "Client" : "Unknown";
89-
InitializeTextLine($"Type: {hostType}", out m_TextHostType);
90-
InitializeTextLine("No Stat", out m_TextStat);
91-
}
92-
93-
void InitializeTextLine(string defaultText, out TextMeshProUGUI textComponent)
94-
{
95-
var rootGO = new GameObject("UI Stat Text");
96-
textComponent = rootGO.AddComponent<TextMeshProUGUI>();
97-
textComponent.fontSize = 24;
98-
textComponent.text = defaultText;
99-
textComponent.horizontalAlignment = HorizontalAlignmentOptions.Left;
100-
textComponent.verticalAlignment = VerticalAlignmentOptions.Middle;
101-
textComponent.raycastTarget = false;
102-
textComponent.autoSizeTextContainer = true;
103-
104-
var rectTransform = rootGO.GetComponent<RectTransform>();
105-
Editor.NetworkOverlay.Instance.AddToUI(rectTransform);
94+
Editor.NetworkOverlay.Instance.AddTextToUI("UI Host Type Text", $"Type: {hostType}", out m_TextHostType);
95+
Editor.NetworkOverlay.Instance.AddTextToUI("UI Stat Text", "No Stat", out m_TextStat);
96+
Editor.NetworkOverlay.Instance.AddTextToUI("UI Bad Conditions Text", "", out m_TextBadNetworkConditions);
10697
}
10798

10899
void FixedUpdate()
@@ -124,6 +115,28 @@ void FixedUpdate()
124115
if (m_TextStat != null)
125116
{
126117
m_TextToDisplay = $"RTT: {(m_BossRoomRTT.Average * 1000).ToString("0")} ms;\nUTP RTT {m_UtpRTT.Average.ToString("0")} ms";
118+
if (m_UtpRTT.Average > k_BadNetworkConditionsRTTThreshold)
119+
{
120+
m_TextStat.color = Color.red;
121+
}
122+
else if (m_UtpRTT.Average > k_StrugglingNetworkConditionsRTTThreshold)
123+
{
124+
m_TextStat.color = Color.yellow;
125+
}
126+
else
127+
{
128+
m_TextStat.color = Color.white;
129+
}
130+
}
131+
132+
if (m_TextBadNetworkConditions != null)
133+
{
134+
// Right now, we only base this warning on UTP's RTT metric, but in the future we could watch for packet loss as well, or other metrics.
135+
// This could be a simple icon instead of doing heavy string manipulations.
136+
m_TextBadNetworkConditions.text = m_UtpRTT.Average > k_BadNetworkConditionsRTTThreshold ? "Bad Network Conditions Detected!" : "";
137+
var color = Color.red;
138+
color.a = Mathf.PingPong(Time.time, 1f);
139+
m_TextBadNetworkConditions.color = color;
127140
}
128141
}
129142
else

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ Additional documentation and release notes are available at [Multiplayer Documen
99
## [Unreleased] - yyyy-mm-dd
1010

1111
### Added
12+
feat: bad network conditions warning [MTT-3242] (#632)
1213
feat: adding RNSM (Runtime Network Stats Monitor) to boss room [MTT-3267] (#621)
1314
Added basic automated testing and CI (#484) (#487) (#639)
1415
feat: connection feedback + IP connection window [MTT-2315] [MTT-3234] (#613)
1516
First import of all the vandal imp artwork (#637)
1617
feat: other players loading progress in loading screen [MTT-2239] (#580)
1718
feat: auto reconnect [MTT-2617] (#611)
19+
feat: bumping relay version so we now have auto region selection (with the QoS package). This allows selecting the right relay region instead of the default us-central and should reduce latency for non-central folks. (#657)
1820

1921
### Changed
2022
fix: remove initial ugs popup [MTT-3563] (#650) --> Users who do not use UGS will no longer receive a popup when starting the application telling them how to set it up. It is replaced with a tooltip that appears when hovering on the "Start with Lobby" button with the cursor.
2123
chore: bump NGO to pre.9 (#643)
2224
chore: bump boss room to 2021 [MTT-3022] (#620)
2325
fix: folders and assemblies refactor MTT-2623, MTT-2615 (#628)
26+
feat: updated boss room's root scene to automatically load child scenes at editor time (#653)
2427

2528
### Removed
2629
chore: remove UNET [MTT-3435] (#638) --> removed deprecated UNET transport from Boss Room

Packages/com.unity.multiplayer.samples.coop/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Added
66
feat: other players loading progress in loading screen [MTT-2239] (#580)
7+
feat: adding editor child scene loader for composed scenes (#653)
78

89
### Changed
910

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
using System;
2+
using System.Collections.Generic;
3+
#if UNITY_EDITOR
4+
using UnityEditor;
5+
using UnityEditor.SceneManagement;
6+
#endif
7+
using UnityEngine;
8+
using UnityEngine.SceneManagement;
9+
10+
/// <summary>
11+
/// Allows setting a scene as a root scene and setting its child scenes. To use this, drag this component on any object in a scene to make that scene a root scene. In the background, ChildSceneLoader will automatically manage this.
12+
/// </summary>
13+
public class EditorChildSceneLoader : MonoBehaviour
14+
{
15+
#if UNITY_EDITOR
16+
[SerializeField]
17+
public List<SceneAsset> ChildScenesToLoadConfig;
18+
19+
void Update()
20+
{
21+
// DO NOT DELETE keep this so we can enable/disable this script... (used in ChildSceneLoader)
22+
}
23+
24+
public void SaveSceneSetup()
25+
{
26+
ChildScenesToLoadConfig ??= new();
27+
ChildScenesToLoadConfig.Clear();
28+
foreach (var sceneSetup in EditorSceneManager.GetSceneManagerSetup())
29+
{
30+
ChildScenesToLoadConfig.Add(AssetDatabase.LoadAssetAtPath<SceneAsset>(sceneSetup.path));
31+
}
32+
}
33+
34+
public void ResetSceneSetupToConfig()
35+
{
36+
var sceneAssetsToLoad = ChildScenesToLoadConfig;
37+
38+
List<SceneSetup> sceneSetupToLoad = new();
39+
foreach (var sceneAsset in sceneAssetsToLoad)
40+
{
41+
sceneSetupToLoad.Add(new SceneSetup() { path = AssetDatabase.GetAssetPath(sceneAsset), isActive = false, isLoaded = true });
42+
}
43+
44+
sceneSetupToLoad[0].isActive = true;
45+
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
46+
EditorSceneManager.RestoreSceneManagerSetup(sceneSetupToLoad.ToArray());
47+
}
48+
#endif
49+
}
50+
51+
#if UNITY_EDITOR
52+
[CustomEditor(typeof(EditorChildSceneLoader))]
53+
public class ChildSceneLoaderInspectorGUI : Editor
54+
{
55+
public override void OnInspectorGUI()
56+
{
57+
base.OnInspectorGUI();
58+
59+
var currentInspectorObject = (EditorChildSceneLoader)target;
60+
61+
if (GUILayout.Button("Save scene setup to config"))
62+
{
63+
currentInspectorObject.SaveSceneSetup();
64+
}
65+
66+
if (GUILayout.Button("Reset scene setup from config..."))
67+
{
68+
currentInspectorObject.ResetSceneSetupToConfig();
69+
}
70+
}
71+
}
72+
73+
[InitializeOnLoad]
74+
public class ChildSceneLoader
75+
{
76+
static ChildSceneLoader()
77+
{
78+
EditorSceneManager.sceneOpened += OnSceneLoaded;
79+
}
80+
81+
static void OnSceneLoaded(Scene _, OpenSceneMode mode)
82+
{
83+
if (mode != OpenSceneMode.Single || BuildPipeline.isBuildingPlayer) return; // try to load child scenes only for root scenes or if not building
84+
85+
var scenesToLoadObjects = GameObject.FindObjectsOfType<EditorChildSceneLoader>();
86+
if (scenesToLoadObjects.Length > 1)
87+
{
88+
throw new Exception("Should only have one root scene at once loaded");
89+
}
90+
91+
if (scenesToLoadObjects.Length == 0 || !scenesToLoadObjects[0].enabled) // only when we have a config and when that config is enabled
92+
{
93+
return;
94+
}
95+
96+
scenesToLoadObjects[0].ResetSceneSetupToConfig();
97+
98+
Debug.Log("Setup done for root scene and child scenes");
99+
}
100+
}
101+
#endif

Packages/com.unity.multiplayer.samples.coop/Utilities/EditorChildSceneLoader.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.multiplayer.samples.coop/Utilities/Net/UnityRelayUtilities.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ public static async
2727
throw new Exception($"Creating allocation request has failed: \n {exception.Message}");
2828
}
2929

30-
Debug.Log($"server: {allocation.ConnectionData[0]} {allocation.ConnectionData[1]}");
31-
Debug.Log($"server: {allocation.AllocationId}");
30+
Debug.Log($"server: connection data: {allocation.ConnectionData[0]} {allocation.ConnectionData[1]}, allocation ID:{allocation.AllocationId}, region:{allocation.Region}");
3231

3332
try
3433
{

Packages/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"com.unity.render-pipelines.universal": "12.1.6",
1616
"com.unity.services.authentication": "1.0.0-pre.4",
1717
"com.unity.services.lobby": "1.0.0-pre.6",
18-
"com.unity.services.relay": "1.0.1-pre.5",
18+
"com.unity.services.relay": "1.0.2",
1919
"com.unity.test-framework": "1.1.31",
2020
"com.unity.textmeshpro": "3.0.6",
2121
"com.unity.timeline": "1.6.4",

0 commit comments

Comments
 (0)