Exemple #1
0
    /// <summary>
    /// 登录按钮click方法
    /// </summary>
    private void LoginBtnClick()
    {
        RegistLogin registLogin = GameObject.Find("NetManager").GetComponent <RegistLogin>();
        WindowBase  msgBox      = UIManager.Instance.CreateOrShowWindow("LoginRegistMessageBox", transform);

        registLogin.msgBox = msgBox;

        if (SocketBase._isLogin)
        {
            return;
        }
        SocketBase._netWorker.Stop();
        SocketBase._netWorker.Connect(registLogin._serverAddress);
        while (!SocketBase._netWorker.IsConnect() || SocketBase._netWorker.GetSocket() == null)
        {
            if (!registLogin.WaitTime(SocketBase._waitTimeOut))
            {
                //Debug.Log("连接超时");
                msgBox.buttonsList[0].gameObject.SetActive(true);
                msgBox.textDic["Text_Tip"].text = "连接超时";
                return;
            }
        }
        LoginREQ req = new LoginREQ();

        req.AccountName = inputFieldDic["InputField_Username"].text;
        req.Password    = inputFieldDic["InputField_Password"].text;
        SocketBase._netWorker.SendMessage(req);
    }
Exemple #2
0
    //点击登录按钮触发事件
    private void LoginBtnClick()
    {
        if (_isLogin)
        {
            return;
        }
        //先把Socket指向null
        _netWorker.Stop();

        //连接
        _netWorker.Connect(_serverAddress);

        //判断是否连接超时
        while (!_netWorker.IsConnect() || _netWorker.GetSocket() == null)
        {
            if (!WaitTime(_waitTimeOut))
            {
                Debug.Log("连接超时");
                return;
            }
        }

        //连接服务器成功 -> 给服务器发送数据进行  登录
        LoginREQ req = new LoginREQ();

        req.AccountName = usernameField.text;
        req.Password    = passwordField.text;
        _netWorker.SendMessage(req);
    }