Exemplo n.º 1
0
    public void BtnStartGame()
    {
        string _txtInput = _nameInputField.text.Trim();

        if (_txtInput.Length < 6)
        {
            _txtMessage.text = "Please enter a password at least 6 characters!";
        }
        else
        {
            _txtMessage.text = "Checking name...";
            StartCoroutine(ServerAdapter.CheckNameCreateHero(_txtInput, result =>
            {
                if (result.StartsWith("Error"))
                {
                    _txtMessage.text = result;
                }
                else
                {
                    _txtMessage.text = "Creating hero...";
                    int idih         = -1;
                    for (int i = 0; i < SplitDataFromServe._heroInits.Length; i++)
                    {
                        if (SplitDataFromServe._heroInits[i].name == listClass[lastIdHeroSelected])
                        {
                            idih = int.Parse(SplitDataFromServe._heroInits[lastIdHeroSelected].idih);
                            break;
                        }
                    }
                    if (idih == -1)
                    {
                        _txtMessage.text = "Id class hero is wrong!";
                    }
                    else
                    {
                        StartCoroutine(ServerAdapter.ExecuteCreateHero(idih, _txtInput, result2 =>
                        {
                            if (result2.StartsWith("Error"))
                            {
                                _txtMessage.text = result2;
                            }
                            else
                            {
                                _txtMessage.text = "Create your hero successfully!";
                                var N            = JSON.Parse(result2);
                                PlayerPrefabsController.SetStringData(Constant.IDHERO_CURRENTPLAY, N["hero"]["idh"].Value);
                                StartCoroutine(ServerAdapter.LoadDetailHero(N["hero"]["idcode"].Value, int.Parse(N["hero"]["idh"].Value), result3 =>
                                {
                                    if (result3.StartsWith("Error"))
                                    {
                                        _txtMessage.text = result;
                                    }
                                    else
                                    {
                                        SplitDataFromServe.ReadDetailDataHeroCurrentPlay(result3);
                                        Debug.Log("Load scene MainMenu");
                                        StartCoroutine(SceneLoader._instance.LoadNewScene(2));
                                    }
                                }));
                            }
                        }));
                    }
                }
            }));
        }
    }