using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using WW;


public class Test_Ping : MonoSingleton<Test_Ping> {


    private string IP = "192.168.1.1";
    Ping ping;
    float delayTime;
    private UILabel pingFps;
    public bool isStart;
    private void Awake()
    {
       // Log.error("进来");
        pingFps = gameObject.GetComponent<UILabel>();
    }
    void Start()
    {
        gameObject.SetActive(false);
        isStart = false;
        IP = GameLoadInitial.testPingServerUrl.Replace(":10001","");
        Log.error(IP);
        SendPing();
        InvokeManager.addTimeCount(() => { ping = new Ping(IP); }, 1f, InvokeManager.FOREVER);
    }
    private void Update()
    {
        
        if (null != ping && ping.isDone)
        {
            // Debug.Log(22);
            delayTime = ping.time;
            pingFps.text = delayTime.ToString()+"ms";
            Debug.Log(delayTime);
            ping.DestroyPing();
            ping = null;
           // Invoke("SendPing", 0.1F);//每秒Ping一次
        }
    }
   
    void SendPing()
    {
        ping = new Ping(IP);
    }
}
Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐