Skip to content

Commit 1288950

Browse files
committed
extracted duplicated methods to NetworkOverlay
1 parent e3857f2 commit 1288950

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,7 @@ void CreateLatencyText()
6767
Assert.IsNotNull(NetworkOverlay.Instance,
6868
"No NetworkOverlay object part of scene. Add NetworkOverlay prefab to bootstrap scene!");
6969

70-
var statUI = new GameObject("UI Latency Warning Text");
71-
72-
m_LatencyText = statUI.AddComponent<TextMeshProUGUI>();
73-
m_LatencyText.fontSize = 32;
74-
m_LatencyText.horizontalAlignment = HorizontalAlignmentOptions.Left;
75-
m_LatencyText.verticalAlignment = VerticalAlignmentOptions.Middle;
76-
m_LatencyText.raycastTarget = false;
77-
m_LatencyText.autoSizeTextContainer = true;
78-
79-
m_LatencyText.text = "Network Latency Enabled";
80-
81-
var statUIRectTransform = statUI.GetComponent<RectTransform>();
82-
NetworkOverlay.Instance.AddToUI(statUIRectTransform);
70+
NetworkOverlay.Instance.AddTextToUI("UI Latency Warning Text", "Network Latency Enabled", out m_LatencyText);
8371
}
8472
}
8573
}

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

Lines changed: 16 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 = 32;
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)

Assets/BossRoom/Scripts/Infrastructure/NetworkStats.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,9 @@ void CreateNetworkStatsText()
9191
"No NetworkOverlay object part of scene. Add NetworkOverlay prefab to bootstrap scene!");
9292

9393
string hostType = IsHost ? "Host" : IsClient ? "Client" : "Unknown";
94-
InitializeTextLine($"Type: {hostType}", out m_TextHostType);
95-
InitializeTextLine("No Stat", out m_TextStat);
96-
InitializeTextLine("", out m_TextBadNetworkConditions);
97-
}
98-
99-
void InitializeTextLine(string defaultText, out TextMeshProUGUI textComponent)
100-
{
101-
var rootGO = new GameObject("UI Stat Text");
102-
textComponent = rootGO.AddComponent<TextMeshProUGUI>();
103-
textComponent.fontSize = 32;
104-
textComponent.text = defaultText;
105-
textComponent.horizontalAlignment = HorizontalAlignmentOptions.Left;
106-
textComponent.verticalAlignment = VerticalAlignmentOptions.Middle;
107-
textComponent.raycastTarget = false;
108-
textComponent.autoSizeTextContainer = true;
109-
110-
var rectTransform = rootGO.GetComponent<RectTransform>();
111-
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);
11297
}
11398

11499
void FixedUpdate()

0 commit comments

Comments
 (0)