學習一下關於Unity3d的當前網絡狀態的情況,分享如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NetWorkPlatform : MonoBehaviour
{
public Text OutPutText;
// Use this for initialization
void Start()
{
OutPutText.text = "";
IsNetWorkReachability();
}
public void IsNetWorkReachability()
{
switch (Application.internetReachability)
{
case NetworkReachability.ReachableViaLocalAreaNetwork:
Debug.Log("當前使用的是WIFI,請放心使用!");
OutPutText.text = "當前使用的是WIFI,請放心使用!";
break;
case NetworkReachability.ReachableViaCarrierDataNetwork:
Debug.Log("當前使用的是移動網絡,是否繼續更新!");
OutPutText.text = "當前使用的是移動網絡,是否繼續更新!";
break;
case NetworkReachability.NotReachable:
Debug.Log("當前沒有聯網,請您先聯網後進行操作!");
OutPutText.text = "當前沒有聯網,請您先聯網後進行操作!";
break;
default:
break;
}
}
}