Ejemplo n.º 1
0
    static public void SaveProfile(string name, int calculBestScore, int tableBestScore)
    {
        // open existing profiles
        ExistingProfiles existProfiles = new ExistingProfiles();

        if (File.Exists(pathProfile))
        {
            string jsonFile = System.IO.File.ReadAllText(pathProfile);
            existProfiles = JsonUtility.FromJson <ExistingProfiles>(jsonFile);
        }
        else
        {
            File.Create(pathProfile).Close();
            existProfiles          = new ExistingProfiles();
            existProfiles.lastID   = 0;
            existProfiles.profiles = new List <ProfileData>();
        }

        // new profile data
        ProfileData data = new ProfileData();

        existProfiles.lastID += 1;
        data.id              = existProfiles.lastID;
        data.name            = name;
        data.calculBestScore = calculBestScore;
        data.tableBestScore  = tableBestScore;

        //add profile
        existProfiles.profiles.Add(data);
        string json = JsonUtility.ToJson(existProfiles);

        File.WriteAllText(pathProfile, json);
        existProfiles = JsonUtility.FromJson <ExistingProfiles>(json);
    }
Ejemplo n.º 2
0
    static public void UpdateProfile(string name, int calculBestScore, int tableBestScore)
    {
        // open existing profiles
        ExistingProfiles existProfiles = new ExistingProfiles();

        if (File.Exists(pathProfile))
        {
            string jsonFile = System.IO.File.ReadAllText(pathProfile);
            existProfiles = JsonUtility.FromJson <ExistingProfiles>(jsonFile);
        }
        else
        {
            File.Create(pathProfile).Close();
            existProfiles          = new ExistingProfiles();
            existProfiles.lastID   = 0;
            existProfiles.profiles = new List <ProfileData>();
        }

        foreach (ProfileData profileData in existProfiles.profiles) // find matching profile
        {
            if (profileData.name == name)
            {
                profileData.name            = name;
                profileData.calculBestScore = calculBestScore;
                profileData.tableBestScore  = tableBestScore;
            }
        }

        string json = JsonUtility.ToJson(existProfiles);

        File.WriteAllText(pathProfile, json);
        existProfiles = JsonUtility.FromJson <ExistingProfiles>(json);
    }
Ejemplo n.º 3
0
    static public ExistingProfiles LoadAllProfiles()
    {
        pathProfile = Application.persistentDataPath + "/profileInfo.json";
        ExistingProfiles existProfiles = null;

        if (File.Exists(pathProfile)) // file exists
        {
            string jsonFile = System.IO.File.ReadAllText(pathProfile);
            existProfiles = JsonUtility.FromJson <ExistingProfiles>(jsonFile);
        }
        return(existProfiles);
    }
Ejemplo n.º 4
0
    void dropDownUpdate()
    {
        ExistingProfiles existProfiles = ProfileManagement.LoadAllProfiles();

        profileDrop.options.Clear();
        if (existProfiles != null)
        {
            List <string> profileNames = new List <string>();
            //Debug.Log("EXIST "+existProfiles);
            foreach (ProfileData profile in existProfiles.profiles)
            {
                profileNames.Add(profile.name);
                //Debug.Log("Profile FOUND "+profile.name);
            }
            profileDrop.AddOptions(profileNames);
        }
    }
Ejemplo n.º 5
0
    static public ProfileData LoadProfile(string name)
    {
        ProfileData myProfile = null;

        if (File.Exists(pathProfile)) // file exists
        {
            string           jsonFile      = System.IO.File.ReadAllText(pathProfile);
            ExistingProfiles existProfiles = JsonUtility.FromJson <ExistingProfiles>(jsonFile);
            foreach (ProfileData profileData in existProfiles.profiles) // find matching profile
            {
                if (profileData.name == name)
                {
                    myProfile = profileData;
                }
            }
        }
        Debug.Log("Profile LOADED ! " + myProfile.name + " id: " + myProfile.id + " bestScoreCalcul: " + myProfile.calculBestScore);
        return(myProfile);
    }
Ejemplo n.º 6
0
    static public void RemoveProfile(string name)
    {
        // open existing profiles
        ExistingProfiles existProfiles = new ExistingProfiles();

        if (File.Exists(pathProfile))
        {
            string jsonFile = System.IO.File.ReadAllText(pathProfile);
            existProfiles = JsonUtility.FromJson <ExistingProfiles>(jsonFile);
            ProfileData profileToRemove = null;
            foreach (ProfileData profileData in existProfiles.profiles) // find matching profile
            {
                if (profileData.name == name)
                {
                    profileToRemove = profileData;
                }
            }
            existProfiles.profiles.Remove(profileToRemove);
            string json = JsonUtility.ToJson(existProfiles);
            File.WriteAllText(pathProfile, json);
            existProfiles = JsonUtility.FromJson <ExistingProfiles>(json);
        }
    }