- Home /
Question by
PeroChield · Apr 30, 2018 at 02:58 PM ·
uijsonscript error
I don't understand how save to QualitySettings.SetQuality with a json file
I want someone to fix what I've sent and thank you. There is my SettingsManager script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
public class SettingsManager : MonoBehaviour {
public Dropdown textureQualityDropdown;
public GameSettings gameSettings;
public Button applyButton;
void OnEnable()
{
textureQualityDropdown.onValueChanged.AddListener(delegate {
OnTextureQualityDrowpon(); });
applyButton.onClick.AddListener(delegate { OnApplyButtonClick(); });
LoadSettings();
}
public void OnTextureQualityDrowpon()
{
QualitySettings.SetQualityLevel (gameSettings.textureQuality = textureQualityDropdown.value);
}
public void OnApplyButtonClick()
{
SaveSettings();
}
public void SaveSettings()
{
public void SaveSettings()
{
string jsonData = JsonUtility.ToJson(gameSettings, true);
File.WriteAllText(Application.persistentDataPath + "/gamesettings.json", jsonData);
}
public void LoadSettings()
{
File.ReadAllText(Application.persistentDataPath + "/gamesettings.json");
gameSettings = JsonUtility.FromJson<GameSettings>(File.ReadAllText(Application.persistentDataPath + "/gamesettings.json"));
textureQualityDropdown.value = gameSettings.textureQuality;
}
}
And other is my GameSettings script:
public class GameSettings{
public int textureQuality;
}
I have another question to ask about how to setup a slider and an input field to takes value ? Thank you for your answers. Because I'm started a Unity program 3 weeks ago.
Comment
Best Answer
Answer by SharkoFR · Apr 30, 2018 at 05:10 PM
Hi!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO; /// ADD THIS
public class tuto : MonoBehaviour {
public void saveSettings()
{
string jsonData = JsonUtility.ToJson(gameSettings, true);
using (StreamWriter sr = new StreamWriter(Application.persistentDataPath + @"/gamesettings.json"))
{
sr.WriteLine(jsonData);
}
}
}
add using System.IO; and the lines i gived to you, i answer later for your second question
sorry I did not pay attention to what I wrote! Should i type it that
QualitySettings.SetQualityLevel (gameSettings.textureQuality = textureQualityDropdown.value);
ins$$anonymous$$d of
QualitySettings.SetQualityLevel() =gameSettings.textureQuality = textureQualityDropdown.value;
but I've tried this and it did not work.... Thank you for answer!
For slider there are few videos on youtube, it's very simple!