示例#1
0
        /// <summary>
        /// 断线重连
        /// </summary>
        public IEnumerator  ReConnect()
        {
            ReConnectState = true;
            while (WebData.Instance().RecTimes <= 10)
            {
                WebData.Instance().RecTimes += 1;
                yield return(new WaitForSeconds(5));

                if (!WebData.Instance().IsReconnect)
                {
                    Debug.Log("第" + WebData.Instance().RecTimes + "次重连尝试");
                    WebData.Instance().OpenWebSocket();
                }
                else
                {
                    ReConnectState = false;
                    break;
                }
            }
            if (WebData.Instance().RecTimes > 10)
            {
                Debug.LogError("网络断开");
                //客户端断开网络退出应用
                //Application.Quit();
                SceneMsg msg = new SceneMsg("login",
                                            delegate() {
                    Debug.Log("场景加载完成");
                    Dispatch(AreaCode.UI, UIEvent.LOG_ACTIVE, true);
                });
                //
                Dispatch(AreaCode.SCENE, SceneEvent.LOGIN_PLAY_SCENE, msg);
            }
        }
示例#2
0
        public static WebData Instance()

        {
            if (_instance == null)

            {
                lock (LockHelper)

                {
                    if (_instance == null)
                    {
                        _instance = new WebData();
                    }
                }
            }

            return(_instance);
        }
        /// <summary>
        /// 断线重连
        /// </summary>
        public IEnumerator ReConnect()
        {
            ReConnectState = true;
            while (WebData.Instance().RecTimes <= 5)
            {
                yield return(new WaitForSeconds(1));

                if (!WebData.Instance().IsReconnect)
                {
                    Debug.Log("第" + WebData.Instance().RecTimes + "次重连尝试");
                    //WebData.Instance().OpenWebSocket();
                }
                else
                {
                    ReConnectState = false;
                    break;
                }
                WebData.Instance().RecTimes += 1;
            }
            if (WebData.Instance().RecTimes > 5)
            {
                promptMsg.Change(LanguageService.Instance.GetStringByKey("与服务器断开连接", string.Empty), Color.white);
                Debug.LogError("网络断开");
                //SceneMsg msg = new SceneMsg("login",
                //    delegate ()
                //    {
                //        Debug.Log("场景加载完成");
                //        Dispatch(AreaCode.UI, UIEvent.LOGINSELECT_PANEL_ACTIVE, true);
                //    });
                WebData.isLogin = false;
                //Dispatch(AreaCode.SCENE, SceneEvent.MENU_PLAY_SCENE, msg);
                StopCoroutine(ReConnect());
                Dispatch(AreaCode.UI, UIEvent.HINT_ACTIVE, promptMsg);
                WebData.Instance().RecTimes = 0;
            }
        }
示例#4
0
 private void Start()
 {
     _wabData = WebData.Instance();
     _address = _wabData.Address;
     _text    = _wabData.Text;
 }