From f1a86ee66e56f46d60fac3a516cb031c00a09ab2 Mon Sep 17 00:00:00 2001 From: vis2k Date: Mon, 3 Oct 2022 13:20:05 +0200 Subject: [PATCH] GUI --- Assets/Mirror/Core/NetworkClient.cs | 23 +++++++++++++++++++++++ Assets/Mirror/Core/NetworkManager.cs | 10 ++++++++++ 2 files changed, 33 insertions(+) diff --git a/Assets/Mirror/Core/NetworkClient.cs b/Assets/Mirror/Core/NetworkClient.cs index 1584cb693..2813d22c8 100644 --- a/Assets/Mirror/Core/NetworkClient.cs +++ b/Assets/Mirror/Core/NetworkClient.cs @@ -1639,5 +1639,28 @@ public static void Shutdown() OnDisconnectedEvent = null; OnErrorEvent = null; } + // GUI ///////////////////////////////////////////////////////////////// + // called from NetworkManager to display timeline interpolation status. + // useful to indicate catchup / slowdown / dynamic adjustment etc. + internal static void OnGUI() + { + // only if in world + if (!ready) return; + + GUILayout.BeginArea(new Rect(10, 5, 400, 50)); + + GUILayout.BeginHorizontal("Box"); + GUILayout.Label("Snapshot Interp.:"); + // color while catching up / slowing down + if (localTimescale > 1) GUI.color = Color.green; // green traffic light = go fast + else if (localTimescale < 1) GUI.color = Color.red; // red traffic light = go slow + else GUI.color = Color.white; + GUILayout.Box($"timeline: {localTimeline:F2}"); + GUILayout.Box($"buffer: {snapshots.Count}"); + GUILayout.Box($"timescale: {localTimescale:F2}"); + GUILayout.EndHorizontal(); + + GUILayout.EndArea(); + } } } diff --git a/Assets/Mirror/Core/NetworkManager.cs b/Assets/Mirror/Core/NetworkManager.cs index d1fb89e99..30fbea40e 100644 --- a/Assets/Mirror/Core/NetworkManager.cs +++ b/Assets/Mirror/Core/NetworkManager.cs @@ -105,6 +105,9 @@ public class NetworkManager : MonoBehaviour public static List startPositions = new List(); public static int startPositionIndex; + [Header("Debug")] + public bool timeInterpolationGui = false; + /// The one and only NetworkManager public static NetworkManager singleton { get; internal set; } @@ -1342,5 +1345,12 @@ public virtual void OnStopClient() {} /// This is called when a host is stopped. public virtual void OnStopHost() {} + + // GUI ///////////////////////////////////////////////////////////////// + void OnGUI() + { + if (!timeInterpolationGui) return; + NetworkClient.OnGUI(); + } } }