コード例 #1
0
ファイル: Login.cs プロジェクト: DarshaniNA/GermHunter_Game
    IEnumerator Submit()
    {
        WWW       www;
        Hashtable postHeader = new Hashtable();

        postHeader.Add("Content-Type", "application/json");

        LoginObject postData = new LoginObject();

        postData.Username = userName.text;
        postData.Password = userPassword.text;

        var jsonData = JsonMapper.ToJson(postData);

        //var formData = System.Text.Encoding.UTF8.GetBytes("{'Username':'******', 'Password':'******'}");
        if (Constant.CheckNetworkAvailability())
        {
            www = new WWW(Constant.LOGIN_URL, System.Text.Encoding.UTF8.GetBytes(jsonData), postHeader);

            yield return(www);

            if (www.text.Equals("null"))
            {
                alertText.text = "Check Your User Name Password";
            }
            //else if (www.text != null)
            //{
            //    string[] msg = www.text.Split(char.Parse(":"));
            //    if (msg[1].Equals("\"An error has occurred.\"}"))
            //    {
            //        print("An error has occurred!!!!!!!!!!!!!");
            //    }
            //}
            else
            {
                Debug.Log("request success");
                alertText.text = "Login Success";
                landingPanel.SetActive(true);

                //loginPannel.enabled = false;
                print(www.text);

                var userData = JsonMapper.ToObject <PlayerObject>(www.text);
                PlayerPrefsUtil.SavePlayer(userData);
                titleText.text = "Hi " + userData.Name.ToString();
                loggedUsername = userData.Name;

                StartCoroutine(Deactivatetext());
            }
        }
        else
        {
            SSTools.ShowMessage("No Network Connection", SSTools.Position.bottom, SSTools.Time.oneSecond);
        }
    }
コード例 #2
0
    IEnumerator SendScore(int score, int coinScore)
    {
        WWW www;

        Hashtable postHeader = new Hashtable();

        postHeader.Add("Content-Type", "application/json");
        PlayerObject player        = PlayerPrefsUtil.LoadPLayer();
        ScoreObject  postScoreData = new ScoreObject();

        postScoreData.Id         = 1;
        postScoreData.PlayerId   = player.Id;
        postScoreData.PlayerName = player.Name;
        postScoreData.LevelId    = 4;
        postScoreData.LevelName  = "Basic";
        postScoreData.Time       = "2019-05-19T02:37:36.725Z";
        postScoreData.Pickups    = coinScore;
        postScoreData.Points     = score;
        postScoreData.TimeRun    = score;

        var jsonData = JsonMapper.ToJson(postScoreData);

        print("score data " + jsonData.ToString());
        //var formData = System.Text.Encoding.UTF8.GetBytes("{'Username':'******', 'Password':'******'}");
        if (Constant.CheckNetworkAvailability())
        {
            www = new WWW(Constant.SCORE_URL, System.Text.Encoding.UTF8.GetBytes(jsonData), postHeader);

            yield return(www);

            if (www.text.Equals("null"))
            {
                print("error error !!!");
            }
            else
            {
                Debug.Log("request success");
                print(www.text);
            }
        }
        else
        {
            SSTools.ShowMessage("No Network Connection", SSTools.Position.bottom, SSTools.Time.oneSecond);
        }
    }
コード例 #3
0
    IEnumerator SendData()
    {
        //const string POST_DATA_URL = "http://gamerdata.gear.host/api/Players";
        WWW       www;
        Hashtable postHeader = new Hashtable();

        postHeader.Add("Content-Type", "application/json");

        var newPlayer = new PlayerObject();

        newPlayer.Name     = userName.text;
        newPlayer.Email    = userEmail.text;
        newPlayer.GamerTag = userNikName.text;
        newPlayer.Password = passord.text;
        newPlayer.Age      = age.text;
        newPlayer.Gender   = gender.text;

        // var jsonData = JsonUtility.ToJson(newPlayer);
        // JsonMapper.ToObject<>

        var jsonData = JsonMapper.ToJson(newPlayer);

        //var formData = System.Text.Encoding.UTF8.GetBytes("{'Name':'" + userName.text
        //    + "', 'Email':'" + userEmail.text
        //    + "', 'GamerTag':'" + userNikName.text
        //    + "', 'Age':'" + age.text
        //    + "', 'Gender':'" + gender.text
        //    + "', 'Password':'******'}");

        if (Constant.CheckNetworkAvailability())
        {
            www = new WWW(Constant.POST_DATA_URL, System.Text.Encoding.UTF8.GetBytes(jsonData), postHeader);

            yield return(www);

            if (www.error != null)
            {
                Debug.Log("request error: " + www.error);
            }
            else
            {
                Debug.Log("request success");
                loginSucessText.enabled = true;
                loginSucessText.text    = "Registration Sucess";

                userName.gameObject.SetActive(false);
                userEmail.gameObject.SetActive(false);
                userNikName.gameObject.SetActive(false);
                passord.gameObject.SetActive(false);
                age.gameObject.SetActive(false);
                gender.gameObject.SetActive(false);
                experiance.gameObject.SetActive(false);
                StartCoroutine(DeactivatePanel());
                StartCoroutine(ActiveFeilds());
            }
        }
        else
        {
            SSTools.ShowMessage("No Network Connection", SSTools.Position.bottom, SSTools.Time.oneSecond);
        }
    }