Ejemplo n.º 1
0
    private IEnumerator ConnectionCheckRoutine()
    {
        while (true)
        {
            yield return(new WaitForSeconds(CONN_CHECK_INTERVAL));

            // Check to see if the network status has changed.
            var currentStatus = Application.internetReachability;
            if (_networkStatus != currentStatus)
            {
                Debug.Log($"Network status changed to: {currentStatus.ToString()}");
                _networkStatus = currentStatus;
                NetworkStatusChanged?.Invoke(_networkStatus);
            }

            // if a network is reachable, check to see if it is connected to the net.
            if (_networkStatus != NetworkReachability.NotReachable)
            {
                UnityWebRequest wr = new UnityWebRequest("http://www.google.com");
                yield return(wr.SendWebRequest());

                if (string.IsNullOrEmpty(wr.error))
                {
                    _hasInternetConnection = true;
                }
                else
                {
                    Debug.Log($"Internet Unreachable: {wr.error}");
                    _hasInternetConnection = false;
                }
            }
            else
            {
                Debug.Log($"Internet Unreachable: {_networkStatus.ToString()}");
                _hasInternetConnection = false;
            }
            UpdateStatusText();
        }
    }
Ejemplo n.º 2
0
 private void NetWorkChange(NetworkReachability preNetWorkStatus, NetworkReachability internetReachability)
 {
     registerText.text = "网络状态变化时触发===》" + internetReachability.ToString();
 }