客户端输入用户名和密码后提交触发

  //登陆
        public void Login(string account, string pass)
        {
            SelectServerData.Instance.SetServerInfo((int)SdkManager.Instance.GetPlatFrom(), account, pass);
            NetworkManager.Instance.canReconnect = false;
            NetworkManager.Instance.Close();
            NetworkManager.Instance.Init(JxBlGame.Instance.LoginServerAdress, 49996, NetworkManager.ServerType.LoginServer);
        }


 public void Init(string ip, Int32 port, ServerType type)
        {
            Debugger.Log("set network ip:" + ip + " port:" + port + " type:" + type);
            m_IP = ip;
            m_Port = port;
            serverType = type;
            m_n32ConnectTimes = 0;
            canReconnect = true;
            m_RecvPos = 0;

#if UNITY_EDITOR
            mRecvOverDelayTime = 20000f;
#endif
        }

   public void SetServerInfo(int plafrom, string uin, string sionId) {
            serverPlafrom = plafrom;
            serverUin = uin;
            serverSionId = sionId;
        }

这里写图片描述


这里写图片描述


这里写图片描述



选择服务器和点击 开始按钮 后调用如下:

   //开始游戏
        public void GamePlay()
        {
            int index = SelectServerData.Instance.curSelectIndex;
            SelectServerData.ServerInfo info = SelectServerData.Instance.GetServerDicInfo().ElementAt(index).Value;
            NetworkManager.Instance.canReconnect = false;
            NetworkManager.Instance.Close();
            //info.addr :127.0.0.1     info.port :49998
            NetworkManager.Instance.Init(info.addr, info.port, NetworkManager.ServerType.BalanceServer);
            PlayerPrefs.SetString(SelectServerData.serverKey, info.name);
        }


        public void Init(string ip, Int32 port, ServerType type)
        {
            Debugger.Log("set network ip:" + ip + " port:" + port + " type:" + type);
            m_IP = ip;
            m_Port = port;
            serverType = type;
            m_n32ConnectTimes = 0;
            canReconnect = true;
            m_RecvPos = 0;

#if UNITY_EDITOR
            mRecvOverDelayTime = 20000f;
#endif
        }

这里写图片描述


这里写图片描述



服务器返回:

    Int32 OnNet_OneClinetLoginCheckRet(Stream stream)
    {
        print ("OnNet_OneClinetLoginCheckRet");
        BSToGC.ClinetLoginCheckRet pMsg = ProtoBuf.Serializer.Deserialize<BSToGC.ClinetLoginCheckRet>(stream);
        UInt32 loginSuccess = pMsg.login_success;
        if (loginSuccess != 1)//fail
        {
            LoginCtrl.Instance.LoginFail();
        }
        return (Int32)EErrorCode.eNormal;
    }

FR:海涛高软(hunk Xu) QQ技术交流群:386476712

版权声明:本文为qq_15267341原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_15267341/article/details/79461707