unity3d网络延时检测

                       

王者荣耀里右上角有个网络延时的功能,可以看到当前网络状况。觉得有点意思,网上搜索了一下,找到了这篇文章,转载过来记录一下。
原文章来自Ping,感谢原作者提供好文章

using UnityEngine;using System.Collections;public class Test_Ping : MonoBehaviour{    public string IP = "123.125.114.144";    Ping ping;    float delayTime;    void Start()    {        SendPing();    }    void OnGUI()    {        GUI.color = Color.red;        GUI.Label(new Rect(10, 10, 100, 20), "ping: " + delayTime.ToString() + "ms");        if (null != ping && ping.isDone)        {            delayTime = ping.time;            ping.DestroyPing();            ping = null;            Invoke("SendPing", 1.0F);//每秒Ping一次        }    }    void SendPing()    {        ping = new Ping(IP);    }}
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
           

猜你喜欢

转载自blog.csdn.net/qq_44949818/article/details/89672342
今日推荐