Example #1
0
    //We cannot access directly to an async function, we use LogP1 for get text values and pass to this
    async public void LoginP1(string user, string password)
    {
        try {
            await ws.Login(user, password);

            if (ws.userLogued.Id == -1)
            {
                Text[] listTexts = ImgLoginP1.GetComponentsInChildren <Text>();
                //Error textbox inside loginP1
                listTexts[4].text = "Incorrect user or password";
            }
            else if (ws.userLogued.Id != -1 && ws.userLogued.Id == StaticManager.p2.Id)
            {
                Text[] listTexts = ImgLoginP2.GetComponentsInChildren <Text>();
                //Error textbox inside loginP2
                listTexts[4].text = "User logged by P2";
            }
            else
            {
                TextNameP1.text = user;

                //Update static manager settings for persistence
                StaticManager.p1.Name = user;
                StaticManager.p1.Id   = ws.userLogued.Id;

                enableButtons();

                Text[] listTexts = ImgLoginP1.GetComponentsInChildren <Text>();
                //Clear all textbox on exit
                listTexts[1].text = "";
                listTexts[3].text = "";
                listTexts[4].text = "";

                //Hide login window
                ImgLoginP1.SetActive(false);
            }

            //Hide connection anim
            ImgConnection.SetActive(false);
        }
        catch (Exception ex)
        {
            TextError.text = "Error contacting with login server";
            //Hide login window
            ImgLoginP1.SetActive(false);
            //Hide connection anim
            ImgConnection.SetActive(false);

            enableButtons();
        }
    }