- Home /
Question by
Kek_Kek · Jun 14, 2018 at 02:02 AM ·
jsondeserialization
ArgumentException: Cannot deserialize JSON to new instances of type
Im getting the error on my settings manager script.
SettingManager Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
public class SettingManager : MonoBehaviour {
public Dropdown Vsync;
public Dropdown resolutionDropdown;
public Toggle windowToggle;
public Dropdown AAdropdown;
public Dropdown qualitySettings;
public Resolution[] resolutions;
public GameSettings gameSettings;
/// <summary>
/// Options
/// </summary>
void OnEnable()
{
gameSettings = GetComponent<GameSettings>();
windowToggle.onValueChanged.AddListener(delegate { OnFullscreenToggle(); });
resolutionDropdown.onValueChanged.AddListener(delegate { OnResolutionChange(); });
qualitySettings.onValueChanged.AddListener(delegate { OnTextureQualityChange(); });
AAdropdown.onValueChanged.AddListener(delegate { OnAntiAliasingChange(); });
Vsync.onValueChanged.AddListener(delegate { OnvSyncChange(); });
resolutions = Screen.resolutions;
foreach(Resolution resolution in resolutions)
{
resolutionDropdown.options.Add(new Dropdown.OptionData(resolution.ToString()));
}
if (File.Exists(Application.persistentDataPath + "/gamesettings.json") == true)
{
LoadSettings();
}
}
public void OnFullscreenToggle()
{
gameSettings.fullscreen = Screen.fullScreen = windowToggle.isOn;
}
public void OnResolutionChange()
{
Screen.SetResolution(resolutions[resolutionDropdown.value].width, resolutions[resolutionDropdown.value].height, Screen.fullScreen);
gameSettings.resolutionIndex = resolutionDropdown.value;
}
public void OnTextureQualityChange()
{
QualitySettings.masterTextureLimit = gameSettings.textureQuality = qualitySettings.value;
}
public void OnAntiAliasingChange()
{
QualitySettings.antiAliasing = (int)Mathf.Pow(2, AAdropdown.value);
gameSettings.antialiasing = AAdropdown.value;
}
public void OnvSyncChange()
{
QualitySettings.vSyncCount = gameSettings.vSync = Vsync.value;
}
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"));
AAdropdown.value = gameSettings.resolutionIndex;
Vsync.value = gameSettings.vSync;
qualitySettings.value = gameSettings.textureQuality;
resolutionDropdown.value = gameSettings.resolutionIndex;
windowToggle.isOn = gameSettings.fullscreen;
resolutionDropdown.RefreshShownValue();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
GameManager Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameSettings : MonoBehaviour {
public bool fullscreen;
public int textureQuality;
public int antialiasing;
public int vSync;
public int resolutionIndex;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
Comment