From 527dda561a4e1dd723f3f9d4ddbaba6bf82e7340 Mon Sep 17 00:00:00 2001 From: vis2k Date: Mon, 27 Mar 2023 10:56:13 +0800 Subject: [PATCH] revert previous commit NetworkTime modifications. keep TimeAsDouble --- Assets/Mirror/Core/NetworkTime.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Assets/Mirror/Core/NetworkTime.cs b/Assets/Mirror/Core/NetworkTime.cs index 27798f267..23a8dd83f 100644 --- a/Assets/Mirror/Core/NetworkTime.cs +++ b/Assets/Mirror/Core/NetworkTime.cs @@ -6,7 +6,9 @@ // some users may still be using that. using System.Runtime.CompilerServices; using UnityEngine; +#if !UNITY_2020_3_OR_NEWER using Stopwatch = System.Diagnostics.Stopwatch; +#endif namespace Mirror { @@ -23,15 +25,21 @@ public static class NetworkTime static ExponentialMovingAverage _rtt = new ExponentialMovingAverage(PingWindowSize); + /// Returns double precision clock time _in this system_, unaffected by the network. +#if UNITY_2020_3_OR_NEWER + public static double localTime + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => Time.timeAsDouble; + } +#else // need stopwatch for older Unity versions, but it's quite slow. // CAREFUL: unlike Time.time, this is not a FRAME time. // it changes during the frame too. static readonly Stopwatch stopwatch = new Stopwatch(); - static NetworkTime() => stopwatch.Start(); - - /// Returns double precision clock time _in this system_, unaffected by the network. public static double localTime => stopwatch.Elapsed.TotalSeconds; +#endif /// The time in seconds since the server started. // via global NetworkClient snapshot interpolated timeline (if client). @@ -69,7 +77,9 @@ public static void ResetStatics() PingWindowSize = 6; lastPingTime = 0; _rtt = new ExponentialMovingAverage(PingWindowSize); +#if !UNITY_2020_3_OR_NEWER stopwatch.Restart(); +#endif } internal static void UpdateClient()