예제 #1
0
    //登录状态轮询
    IEnumerator OnPolling()
    {
        while (true)
        {
            UnityWebRequest www = UnityWebRequest.Get(LoginInfo.Instance().mylogindata.URL +
                                                      LoginInfo.Instance().mylogindata.hallaliveAPI +
                                                      "user_id=" + LoginInfo.Instance().mylogindata.user_id +
                                                      "&unionuid=" + LoginInfo.Instance().mylogindata.token);
            yield return(www.Send());

            Debug.Log(www.url);
            if (www.error == null)
            {
                JsonData jd = JsonMapper.ToObject(www.downloadHandler.text);
                if (jd["code"].ToString() == "200")
                {
                    LoginInfo.Instance().mylogindata.ALLScroce = jd["Userinfo"]["quick_credit"].ToString();
                    gold.text = LoginInfo.Instance().mylogindata.ALLScroce;
                    if (jd["Userinfo"]["status"].ToString() == "2")
                    {
                        ShowOtherMess(jd["msg"].ToString());
                        yield return(new WaitForSeconds(2f));

                        tcp.SocketQuit();
                        SceneManager.LoadScene(0);
                    }
                }
                else
                {
                    ShowOtherMess(jd["msg"].ToString());
                    yield return(new WaitForSeconds(2f));

                    tcp.SocketQuit();
                    SceneManager.LoadScene(0);
                }
            }
            yield return(new WaitForSeconds(4f));
        }
    }
예제 #2
0
    /// <summary>
    /// 轮询信息
    /// </summary>
    /// <param name="url"></param>
    /// <returns></returns>
    IEnumerator Polling(string url)
    {
        while (true)
        {
            UnityWebRequest www = UnityWebRequest.Get(url);
            yield return(www.Send());

            if (www.error == null)
            {
                JsonData jd = JsonMapper.ToObject(www.downloadHandler.text);
                if (jd["code"].ToString() == "200")
                {
                    LoginInfo.Instance().mylogindata.ALLScroce = jd["Userinfo"]["quick_credit"].ToString();
                    GoldText.text = LoginInfo.Instance().mylogindata.ALLScroce;
                    if (jd["Userinfo"]["status"].ToString() == "2")
                    {
                        ShowOtherMess(jd["msg"].ToString());
                        yield return(new WaitForSeconds(2f));

                        tcpNet.SocketQuit();
                        SceneManager.LoadScene(0);
                    }
                }
                else
                {
                    ShowOtherMess(jd["msg"].ToString());
                    yield return(new WaitForSeconds(2f));

                    tcpNet = NewTcpNet.GetInstance();
                    SceneManager.LoadScene(0);
                }
            }

            yield return(new WaitForSeconds(4f));
        }
    }
예제 #3
0
 private void OnApplicationQuit()
 {
     tcpNet.SocketQuit();
 }