简体   繁体   English

如何实现精确的时间计数器(毫秒级精度)

[英]How to realize accurate time counter (millisecond precision)

Sorry for my English. 对不起我的英语不好。

I have developed a client-server game on Unity and I need equal time counters on the client and server for synchronization. 我在Unity上开发了一个客户端-服务器游戏,并且需要在客户端和服务器上使用相等的时间计数器进行同步。 On the server side (Java) all is working fine. 在服务器端(Java)上一切正常。

On the client I tried to set Fixed Time-step to 0.001 and count time on FixedUpdate. 在客户端上,我尝试将“固定时间步长”设置为0.001,并在FixedUpdate上计数时间。 It works, but in one thread with other scripts and sometimes lags. 它可以工作,但是与其他脚本在一个线程中有时会滞后。 I became convinced of this in this article 我在本文中对此深信不疑

Also I tried to count time in other threads, but this code gets wrong time (I tried TICK_TIME 1 and 5) 我也试图计算其他线程中的时间,但是这段代码得到了错误的时间(我尝试了TICK_TIME 1和5)

while (started)
         {
             time += TICK_TIME;
             Thread.Sleep(TICK_TIME);
         }

How to realize stable counter? 如何实现稳定计数器? And is it possible in Unity? 在Unity中有可能吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM