Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About SanguineTunic

  • Rank

Personal Information

  • Interests
  1. SanguineTunic

    Unity not saving to Json file anymore?

    Okay, thanks for your help, I'm going to ask someone in the Unity forum.
  2. SanguineTunic

    Unity not saving to Json file anymore?

    I now found one possible cause, after starting the game in built mode with development mode active. When saving it says: I don't get why... The path is exactly the same as it should be. Maybe one of you can find the mistake I made.
  3. SanguineTunic

    Unity not saving to Json file anymore?

    Oh, Sorry. Misunderstood that. This is what comes out when I log the content: <string jsonData = JsonUtility.ToJson(gameSettings, true)> UnityEngine.Debug:Log(Object) SettingManager:SaveSettings() (at Assets/Menu/Main Scripts/SettingManager.cs:130) SettingManager:OnCloseButtonClick() (at Assets/Menu/Main Scripts/SettingManager.cs:126) SettingManager:<OnEnable>m__C() (at Assets/Menu/Main Scripts/SettingManager.cs:43) UnityEngine.EventSystems.EventSystem:Update()
  4. SanguineTunic

    Unity not saving to Json file anymore?

    Hmm, I tested the save section with a debug.Log and it clearly is called when clicking on the apply button. I don't get what is wrong. It worked like a charm at first! So, thanks for your fast reply. I hope there is a solution to my problem anywhere, as what you mentioned about the missing Serializable attribute didn't help.
  5. Hey Community, I have a question about C# and Unity. For my options menu I wrote a script with C#, that worked fine for a while. My problem is to let unity write a .Json file into the LocalLow folder. At first everything went fine and there occurred no errors, but now the file is only generated completely empty. I didn't change anything in the script and Visual Studio doesn't show any errors to me, so I have no clue what is wrong. As I'm only a beginner, I hope anyone of you guys can find what I messed up and give me some advices. Code for the GameSettings using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameSettings { //all variables assigned to their class. public bool fullscreen; public float musicvolume; public float audiovolume; public int difficulty; public bool subtitles; public int Language; public int vsync; public int texturequality; public int resolution; public float gamma; public int antialiasing; public bool autosave; } Code for the SettingManager using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.IO; public class SettingManager : MonoBehaviour { //all variables assigned to their class. public Slider musicvolumeslider; public Toggle fullscreenToggle; public Slider audiovolumeSlider; public Dropdown difficultyDropdown; public Toggle subtitlesToggle; public Dropdown languageDropdown; public Dropdown vsyncDropdown; public Dropdown texturequalityDropdown; public Slider gammaSlider; public Dropdown antialiasingDropdown; public Toggle autosaveToggle; public Dropdown resolutionDropdown; public Button closeButton; public AudioSource musicSource; public Resolution[] resolutions; public GameSettings gameSettings; void OnEnable() { DontDestroyOnLoad(gameObject); musicvolumeslider.onValueChanged.AddListener(delegate { OnMusicVolumeChange(); }); fullscreenToggle.onValueChanged.AddListener(delegate { OnFullscreenToggle(); }); audiovolumeSlider.onValueChanged.AddListener(delegate { OnAudioVolumeChange(); }); difficultyDropdown.onValueChanged.AddListener(delegate { OnDifficultyChange(); }); subtitlesToggle.onValueChanged.AddListener(delegate { OnSubtitlesChange(); }); languageDropdown.onValueChanged.AddListener(delegate { OnLanguageChange(); }); vsyncDropdown.onValueChanged.AddListener(delegate { OnVSyncChange(); }); texturequalityDropdown.onValueChanged.AddListener(delegate { OnTextureQualityChange(); }); gammaSlider.onValueChanged.AddListener(delegate { OnGammaChange(); }); autosaveToggle.onValueChanged.AddListener(delegate { OnAutosaveToggle(); }); antialiasingDropdown.onValueChanged.AddListener(delegate { OnAAChange(); }); resolutionDropdown.onValueChanged.AddListener(delegate { OnResolutionChange(); }); closeButton.onClick.AddListener(delegate { OnCloseButtonClick(); }); musicSource = GameObject.FindGameObjectWithTag("music").GetComponent<AudioSource>(); gameSettings = new GameSettings(); resolutions = Screen.resolutions; foreach (Resolution resolution in resolutions) { resolutionDropdown.options.Add(new Dropdown.OptionData(resolution.ToString())); } LoadSettings(); } public void OnMusicVolumeChange() { musicSource.volume = gameSettings.musicvolume = musicvolumeslider.value; } public void OnResolutionChange() { Screen.SetResolution(resolutions[resolutionDropdown.value].width, resolutions[resolutionDropdown.value].height, Screen.fullScreen); gameSettings.resolution = resolutionDropdown.value; } public void OnFullscreenToggle() { gameSettings.fullscreen = Screen.fullScreen = fullscreenToggle.isOn; } public void OnAudioVolumeChange() { AudioListener.volume = gameSettings.audiovolume = audiovolumeSlider.value; } public void OnDifficultyChange() { //Not Implemented Yet } public void OnSubtitlesChange() { //Not Implemented Yet } public void OnLanguageChange() { if (languageDropdown.value == 0) LocalizationService.Instance.Localization = "English"; if (languageDropdown.value == 1) LocalizationService.Instance.Localization = "German"; if (languageDropdown.value == 2) LocalizationService.Instance.Localization = "French"; if (languageDropdown.value == 3) LocalizationService.Instance.Localization = "Russian"; if (languageDropdown.value == 4) LocalizationService.Instance.Localization = "Italian"; if (languageDropdown.value == 5) LocalizationService.Instance.Localization = "Chinese"; } public void OnVSyncChange() { QualitySettings.vSyncCount = gameSettings.vsync = vsyncDropdown.value; } public void OnTextureQualityChange() { QualitySettings.masterTextureLimit = gameSettings.texturequality = texturequalityDropdown.value; } public void OnGammaChange() { //Not Implemented Yet } public void OnAAChange() { QualitySettings.antiAliasing = (int)Mathf.Pow(2, antialiasingDropdown.value); gameSettings.antialiasing = antialiasingDropdown.value; } public void OnAutosaveToggle() { //Not Implemented Yet } public void OnCloseButtonClick() { SaveSettings(); } public void SaveSettings() { string jsonData = JsonUtility.ToJson(gameSettings, true); File.WriteAllText(Application.persistentDataPath + "/gamesettings.json", jsonData); } public void LoadSettings() { gameSettings = JsonUtility.FromJson<GameSettings>(File.ReadAllText(Application.persistentDataPath + "/gamesettings.json")); audiovolumeSlider.value = gameSettings.audiovolume; antialiasingDropdown.value = gameSettings.antialiasing; gammaSlider.value = gameSettings.gamma; texturequalityDropdown.value = gameSettings.texturequality; vsyncDropdown.value = gameSettings.vsync; languageDropdown.value = gameSettings.Language; subtitlesToggle.isOn = gameSettings.subtitles; Screen.fullScreen = gameSettings.fullscreen; difficultyDropdown.value = gameSettings.difficulty; resolutionDropdown.value = gameSettings.resolution; autosaveToggle.isOn = gameSettings.autosave; musicvolumeslider.value = gameSettings.musicvolume; resolutionDropdown.RefreshShownValue(); } } Hoping for fast help, SanguineTunic
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!