Ejemplo n.º 1
0
        private IEnumerator InitData()
        {
            Debug.LogError("InitData");
            if (rc == null)
            {
                yield break;
            }

            var cg = CGPlayerCmd.CreateBuilder();

            cg.Cmd = "Login";
            var dinfo = DeviceInfo.CreateBuilder();

            dinfo.Did         = StatisticsManager.Instance.DeviceID;
            dinfo.AccountName = PlatformSdkManager.Instance.Uid;
            dinfo.DeviceName  = SystemInfo.deviceModel;
            dinfo.Pid         = PlatformSdkManager.Instance.PlatformID;
            dinfo.Uid         = PlatformSdkManager.Instance.Uid;
            cg.DeviceInfo     = dinfo.Build();
            Bundle bundle;
            var    data = KBEngine.Bundle.GetPacketFull(cg, out bundle);
            var    fail = false;

            yield return(StartCoroutine(rc.SendWaitResponse(data.data, data.fid, (packet) =>
            {
                if (packet.responseFlag == 0)
                {
                    var proto = packet.protoBody as GCPlayerCmd;
                    var cmds = proto.Result.Split(' ');
                    myId = System.Convert.ToInt32(cmds[1]);
                    ObjectManager.objectManager.RefreshMyServerId(myId);
                }
                else
                {
                    fail = true;
                }
            }, bundle)));

            //发送报文超时失败 重新发送给服务器
            if (fail)
            {
                Debug.LogError("InitData Fail");
                yield break;
            }
            Debug.LogError("SendLogin: " + myId);
            SendUserData();
        }