//返回角色界面或者返回登陆界面
 public void OnBack()
 {
     if (messageUser.Characters.Count == 0)
     {
         SekiaLoginFactory.Create();
         Game.EventSystem.Run(EventIdType.CreateCharacterFinish);
     }
     else
     {
         SelectCharacterFactory.Create(messageUser);
         Game.EventSystem.Run(EventIdType.CreateCharacterFinish);
     }
 }
        public static async ETVoid Login(string account, string password)
        {
            SekiaLoginComponent login = Game.Scene.GetComponent <FUIComponent>().Get(FUIType.SekiaLogin).GetComponent <SekiaLoginComponent>();

            Session         sessionRealm = Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);
            A0002_Login_R2C messageRealm = (A0002_Login_R2C)await sessionRealm.Call(new A0002_Login_C2R()
            {
                Account = account, Password = password
            });

            sessionRealm.Dispose();
            login.Prompt.GObject.asTextField.text = "正在登录中...";

            //判断Realm服务器返回结果
            if (messageRealm.Error == ErrorCode.ERR_AccountOrPasswordError)
            {
                login.Prompt.GObject.asTextField.text = "登录失败,账号或密码错误";
                login.AccountInput.Get("Input").GObject.asTextInput.text  = "";
                login.PasswordInput.Get("Input").GObject.asTextInput.text = "";
                login.isLogining = false;
                return;
            }
            //判断通过则登陆Realm成功

            //创建唯一Session
            Session sessionGate = Game.Scene.GetComponent <NetOuterComponent>().Create(messageRealm.GateAddress);

            if (SessionComponent.Instance == null)
            {
                //Log.Debug("创建唯一Session");
                Game.Scene.AddComponent <SessionComponent>().Session = sessionGate;
            }
            else
            {
                SessionComponent.Instance.Session = sessionGate;
            }

            A0003_LoginGate_G2C messageGate = (A0003_LoginGate_G2C)await sessionGate.Call(new A0003_LoginGate_C2G()
            {
                GateLoginKey = messageRealm.GateLoginKey
            });

            //判断登陆Gate服务器返回结果
            if (messageGate.Error == ErrorCode.ERR_ConnectGateKeyError)
            {
                login.Prompt.GObject.asTextField.text = "连接网关服务器超时";
                login.AccountInput.Get("Input").GObject.asTextInput.text  = "";
                login.PasswordInput.Get("Input").GObject.asTextInput.text = "";
                sessionGate.Dispose();
                login.isLogining = false;
                return;
            }
            //判断通过则登陆Gate成功

            login.Prompt.GObject.asTextField.text = "";
            User user = ComponentFactory.Create <User, long>(messageGate.UserID);

            GamerComponent.Instance.MyUser = user;
            //Log.Debug("登陆成功");

            //获取角色信息判断应该进入哪个界面
            A0008_GetUserInfo_G2C messageUser = (A0008_GetUserInfo_G2C)await sessionGate.Call(new A0008_GetUserInfo_C2G());

            //消息中包含了3个CharacterInfo

            //正常的角色等级为正整数
            if (messageUser.Characters.Count == 3 &&
                messageUser.Characters[0].Level == 0 &&
                messageUser.Characters[1].Level == 0 &&
                messageUser.Characters[2].Level == 0)
            {
                //进入创建角色界面
                CreateCharacterFactory.Create(messageUser);
                CreateCharacterComponent creater = Game.Scene.GetComponent <FUIComponent>().Get(FUIType.CreateCharacter).GetComponent <CreateCharacterComponent>();
                creater.Seat = 1; //创建第一个空位的角色
            }
            else if (messageUser.Characters.Count == 3 &&
                     (messageUser.Characters[0].Level > 0 ||
                      messageUser.Characters[1].Level > 0 ||
                      messageUser.Characters[2].Level > 0))
            {
                //进入角色选择界面
                SelectCharacterFactory.Create(messageUser);
            }

            Game.EventSystem.Run(EventIdType.SekiaLoginFinish);
        }
        //请求创建角色 参数:角色位置 角色名 骨骼编号 职业编号
        public static async ETVoid CreateNewCharacter(int seat, string name, int skeleton, int career)
        {
            //模型本身由复数的部件构成 玩家先加载模型编号指定的默认模型再根据身上穿着的装备进行更换装备
            SkeletonType skeletonType = SkeletonType.Man;;
            CareerType   careerType   = CareerType.Warror;

            //将控制器页数转换为消息参数
            string gender = "";

            switch (skeleton)
            {
            case 0:
                gender       = "男";
                skeletonType = SkeletonType.Man;
                break;

            case 1:
                gender       = "女";
                skeletonType = SkeletonType.Women;
                break;

            default:
                break;
            }

            switch (career)
            {
            case 0:
                Log.Debug("创建" + gender + "战士" + " 名称:" + name);
                careerType = CareerType.Warror;
                break;

            case 1:
                Log.Debug("创建" + gender + "法师" + " 名称:" + name);
                careerType = CareerType.Mage;
                break;

            default:
                break;
            }

            CreateCharacterComponent creater = Game.Scene.GetComponent <FUIComponent>().Get(FUIType.CreateCharacter).GetComponent <CreateCharacterComponent>();

            //发送创建角色请求
            A0009_CreateNewCharacter_G2C messageCreate = (A0009_CreateNewCharacter_G2C)await SessionComponent.Instance.Session.Call(new A0009_CreateNewCharacter_C2G()
            {
                Name     = name,
                Skeleton = skeletonType,
                Career   = careerType,
                Seat     = seat
            });

            //判断Gate服务器返回结果
            if (messageCreate.Error == ErrorCode.ERR_CreateNewCharacter)
            {
                creater.Prompt.GObject.asTextField.text = "名称已被占用";
                creater.NameInput.Get("Input").GObject.asTextInput.text = "";
                creater.isCreatingCharacter = false;
                return;
            }
            //判断通过则创建角色成功

            //获取角色信息判断应该进入哪个界面
            A0008_GetUserInfo_G2C messageUser = (A0008_GetUserInfo_G2C)await SessionComponent.Instance.Session.Call(new A0008_GetUserInfo_C2G());

            if (messageUser.Characters.Count == 3 &&
                messageUser.Characters[0].Level == 0 &&
                messageUser.Characters[1].Level == 0 &&
                messageUser.Characters[2].Level == 0)
            {
                //报错
                Log.Error("没有正确创建角色");
            }
            else if (messageUser.Characters.Count == 3 &&
                     (messageUser.Characters[0].Level > 0 ||
                      messageUser.Characters[1].Level > 0 ||
                      messageUser.Characters[2].Level > 0))
            {
                //进入角色选择界面
                SelectCharacterFactory.Create(messageUser);
            }

            Game.EventSystem.Run(EventIdType.CreateCharacterFinish);
        }