Exemplo n.º 1
0
    private IEnumerator WaitAndSend()
    {
        CR_running = true;
        yield return(new WaitForSeconds(cooldownBeforeSend));

        string json = JsonUtility.ToJson(eventsJSON);

        print(json);
        CustomPlayerPrefs.SetString("eventsJSON", json);

        try
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(serverUrl);
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(json);
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    eventsJSON.events.Clear();
                    CR_running = false;
                    CustomPlayerPrefs.DeleteKey("eventsJSON");
                }
                else
                {
                    coroutine = WaitAndSend();
                    StartCoroutine(coroutine);
                }
            }
        }
        catch (Exception ex)
        {
            coroutine = WaitAndSend();
            StartCoroutine(coroutine);
        }
    }
    public void FinishLevel()
    {
        if (oldStars == 0)
        {
            float prop_coin = score / (float)num_coins_start;
            stars = (prop_coin > .5f) ? (prop_coin > .8f ? 2 : 1) : 0;
            if (health > 0)
            {
                stars++;
            }
        }
        else
        {
            stars = oldStars;
        }
        if (this.transform.position.y < 0 || health <= 0)
        {
            stars = 0;
        }
        else
        {
            this.audioSource.PlayOneShot(victorySound);
            CustomPlayerPrefs.SetString("Level", nextLevel);
            CustomPlayerPrefs.SetInt("Score", score + CustomPlayerPrefs.GetInt("Score", 0));
            CustomPlayerPrefs.SetInt("LastStars", stars);
            Helpers.ChangeUserProgress(saveLevel == null ? Application.loadedLevelName : saveLevel, stars);
        }

        if (nextLevel.Contains("boss") && stars > 0 && !Application.loadedLevelName.Contains("boss"))
        {
            Application.LoadLevel(nextLevel);
        }

        else if (!Application.loadedLevelName.Contains("boss") || stars == 0)
        {
            EndScreen end = Instantiate(endScreen, GameObject.Find("UI").transform).GetComponent <EndScreen>();
            end.checkpoint = checkpoint;
            end.nextLevel  = nextLevel;
            Time.timeScale = 0;
            GameObject.Find("music").GetComponent <AudioSource>().mute = true;
        }
    }
Exemplo n.º 3
0
 protected void SetContinueData(string playerName)
 {
     Log.Debug(string.Format("SetContinueData; {0}({1})", CONTINUE_KEY, playerName));
     CustomPlayerPrefs.SetString(CONTINUE_KEY, playerName);
 }