Beispiel #1
0
    private void ShowState(RealNetState state)
    {
        switch (state)
        {
        case RealNetState.NETWORK_NOT_REACH:
            text.text = "网络不可用";
            break;

        case RealNetState.NETWORK_WIFI:
            text.text = "WIFI";
            break;

        case RealNetState.NETWORK_CLASS_2_G:
            text.text = "2G";
            break;

        case RealNetState.NETWORK_CLASS_3_G:
            text.text = "3G";
            break;

        case RealNetState.NETWORK_CLASS_4_G:
            text.text = "4G";
            break;

        case RealNetState.NETWORK_CLASS_UNKNOWN:
            text.text = "UnKown Network";
            break;
        }
    }
 /// <summary>
 /// IOS网络状态改变的回调
 /// </summary>
 /// <param name="status"></param>
 void OnNetStatus(string status)
 {
     try
     {
         realNetState = (RealNetState)int.Parse(status);
     }
     catch (Exception e)
     {
         realNetState = RealNetState.NETWORK_CLASS_UNKNOWN;
     }
 }
    void Awake()
    {
        inst = this;
        this.gameObject.name = "NetReachAbility";
        DontDestroyOnLoad(this.gameObject);
#if UNITY_ANDROID
        //通过该API来实例化导入的arr中对应的类
        javaObj = new AndroidJavaObject("com.pub.myunitylib.Unity2Android");
#elif UNITY_IOS
        int netState = NetReachAbility.InitNetReachAbility();
        realNetState = (RealNetState)netState;
#endif
    }