Exemplo n.º 1
0
    private void Awake()
    {
        int historyEntries = PlayerPrefs.GetInt("historyNumber", 0);

        HistoryEntryClass[] historyData = new HistoryEntryClass[historyEntries];

        string path;
        string loadedData;

        for (int i = 0; i < historyEntries; i++)
        {
            path = Application.streamingAssetsPath + "/HistoryEvents/HistoryEvent" + i + ".json";

            loadedData     = File.ReadAllText(path);
            historyData[i] = JsonUtility.FromJson <HistoryEntryClass>(loadedData);

            switch (PlayerPrefs.GetString("wallpaper", "Default"))
            {
            case "Default":
                BgImage.sprite = Default;
                break;

            case "City":
                BgImage.sprite = city;
                break;

            case "Mountain":
                BgImage.sprite = mountain;
                break;

            case "Lion":
                BgImage.sprite = lion;
                break;
            }
        }

        for (int i = 0; i < historyEntries; i++)
        {
            for (int j = 0; j < historyEntries; j++)
            {
                names[i].text = historyData[i].User;
            }
            for (int j = 0; j < historyEntries; j++)
            {
                type[i].text = historyData[i].EventType;
            }
            for (int j = 0; j < historyEntries; j++)
            {
                score[i].text = historyData[i].Score;
            }
            for (int j = 0; j < historyEntries; j++)
            {
                date[i].text = historyData[i].Time;
            }
        }
    }
Exemplo n.º 2
0
        /*
         * Description: Handles logging the user in with the correct credentials
         */
        private void LoginUser()
        {
            string path = Application.streamingAssetsPath + "/" + _username + ".json";

            if (File.Exists(path))
            {
                //Do the loggging of the in

                string userData = File.ReadAllText(path);

                UserData user = JsonUtility.FromJson <UserData>(userData);

                if (user.AccountLocked)
                {
                    UserAccountLockedText.gameObject.SetActive(true);
                    StartCoroutine(HideErrorTexts());
                    return;
                }

                //Check password validity
                if (_password != user.Password)
                {
                    IncorrectPasswordErrorText.gameObject.SetActive(true);
                    _failedLogins++;
                    StartCoroutine(HideErrorTexts());

                    if (_failedLogins == 3)
                    {
                        user.AccountLocked = true;
                        string[] toJson = { JsonUtility.ToJson(user) };
                        File.WriteAllLines(Application.streamingAssetsPath + "/" + _username + ".json", toJson);
                        _failedLogins = 0;
                    }

                    return;
                }



                PlayerPrefs.SetString("currentUser", _username);

                PlayerPrefs.SetInt("historyNumber", PlayerPrefs.GetInt("historyNumber", 0) + 1);
                HistoryEntryClass newLogIn = new HistoryEntryClass();
                newLogIn.User      = _username;
                newLogIn.EventType = "Login";
                newLogIn.Score     = "N/A";
                newLogIn.Time      = DateTime.Today.ToString();
                string[] dataToSave = { JsonUtility.ToJson(newLogIn) };
                File.WriteAllLines(Application.streamingAssetsPath + "/HistoryEvents/HistoryEvent" + PlayerPrefs.GetInt("historyNumber") + ".json", dataToSave);

                if (user.NewAccount)
                {
                    SceneManager.LoadScene("_Scene_ChangePassword");
                }
                else
                {
                    SceneManager.LoadScene("_Scene_MainMenu");
                }
            }
            else
            {
                UserDoesNotExistText.gameObject.SetActive(true);
                StartCoroutine(HideErrorTexts());
            }
        }