-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding script that displays ping (#1975)
* adding script that displays ping * fixing style * adding mirror icon * Update Assets/Mirror/Components/NetworkPingDisplay.cs Co-authored-by: MrGadget <chris@clevertech.net> * adding DisallowMultipleComponent * adding docs on NetworkPingDisplay Co-authored-by: MrGadget <chris@clevertech.net>
- Loading branch information
1 parent
3db57e5
commit 7e93030
Showing
5 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using UnityEngine; | ||
|
||
namespace Mirror | ||
{ | ||
/// <summary> | ||
/// Component that will display the clients ping in milliseconds | ||
/// </summary> | ||
[DisallowMultipleComponent] | ||
[AddComponentMenu("Network/NetworkPingDisplay")] | ||
[HelpURL("https://mirror-networking.com/docs/Components/NetworkPingDisplay.html")] | ||
public class NetworkPingDisplay : MonoBehaviour | ||
{ | ||
[SerializeField] bool showPing = true; | ||
[SerializeField] Vector2 position = new Vector2(200, 0); | ||
[SerializeField] int fontSize = 24; | ||
[SerializeField] Color textColor = new Color32(255, 255, 255, 80); | ||
|
||
GUIStyle style; | ||
|
||
void Awake() | ||
{ | ||
style = new GUIStyle(); | ||
style.alignment = TextAnchor.UpperLeft; | ||
style.fontSize = fontSize; | ||
style.normal.textColor = textColor; | ||
} | ||
|
||
void OnGUI() | ||
{ | ||
if (!showPing) { return; } | ||
|
||
string text = string.Format("{0}ms", (int)(NetworkTime.rtt * 1000)); | ||
|
||
int width = Screen.width; | ||
int height = Screen.height; | ||
Rect rect = new Rect(position.x, position.y, width - 200, height * 2 / 100); | ||
|
||
GUI.Label(rect, text, style); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Network Ping Display | ||
|
||
Network Ping Display shows the Ping time for clients using OnGUI. | ||
|
||
The Ping time is the moving average of the of the (RTT) Round-trip delay time. RTT is calculated by the PingMessage/PongMessage between the client and server. | ||
|
||
![Inspector](NetworkPingDisplay.png) | ||
|
||
See [Clock Synchronization](../Guides/ClockSync.md) for more info. |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters