Settings are now loaded from and saved to the config.json file. Reworked the UI structure a bit (the script that manage the settings have to be active before the UI is opened to actually take effect at game startup). Fixed several UI bugs (slider deselection, UI labels blocking the sliders, etc).
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
using FishNet.Component.Spawning;
|
||||
using SimpleJSON;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using UnityEngine;
|
||||
using Valve.Newtonsoft.Json;
|
||||
using static ConfigManager;
|
||||
|
||||
public class ConfigManager : MonoBehaviour
|
||||
{
|
||||
@@ -14,8 +14,15 @@ public class ConfigManager : MonoBehaviour
|
||||
[System.Serializable]
|
||||
public class Config
|
||||
{
|
||||
public bool isContinuousLocomotion;
|
||||
public float masterVolume;
|
||||
public bool isContinuousLocomotion = false;
|
||||
public float continuousLocomotionSpeed = 0.5f;
|
||||
public float volumeMaster = 0.5f;
|
||||
public float volumeAmbient = 0.5f;
|
||||
public float volumeMusic = 0.5f;
|
||||
public float volumeSFX = 0.5f;
|
||||
public float volumeUI = 0.5f;
|
||||
public float volumeVO = 0.5f;
|
||||
|
||||
}
|
||||
protected Config currentConfig = new Config();
|
||||
protected string configFileName = "config.json";
|
||||
@@ -48,15 +55,18 @@ public class ConfigManager : MonoBehaviour
|
||||
if (!File.Exists(configFilePath))
|
||||
{
|
||||
fileStream = File.Create(configFilePath);
|
||||
fileStream.Close();
|
||||
|
||||
} else
|
||||
{
|
||||
fileStream = new FileStream(configFilePath, FileMode.Open, FileAccess.Write, FileShare.ReadWrite);
|
||||
//fileStream = new FileStream(configFilePath, FileMode.Open, FileAccess.Write, FileShare.ReadWrite);
|
||||
}
|
||||
StreamWriter writer = new StreamWriter(fileStream);
|
||||
writer.Write(JsonUtility.ToJson(currentConfig));
|
||||
writer.Close();
|
||||
fileStream.Close();
|
||||
//StreamWriter writer = new StreamWriter(fileStream);
|
||||
//writer.Write(JsonUtility.ToJson(currentConfig));
|
||||
//writer.Close();
|
||||
//fileStream.Close();
|
||||
string json = JsonUtility.ToJson(currentConfig, true);
|
||||
File.WriteAllText(configFilePath, json);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,21 +78,16 @@ public class ConfigManager : MonoBehaviour
|
||||
if (!File.Exists(configFilePath))
|
||||
{
|
||||
Debug.LogError("Config file was not found and could not be created: " + configFilePath);
|
||||
return null;
|
||||
return currentConfig;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FileStream fileStream = new FileStream(configFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
Config config = JsonUtility.FromJson<Config>(File.ReadAllText(configFilePath));
|
||||
|
||||
/*FileStream fileStream = new FileStream(configFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
StreamReader reader = new StreamReader(fileStream);
|
||||
Config config = JsonUtility.FromJson<Config>(reader.ReadToEnd());
|
||||
reader.Close();
|
||||
fileStream.Close();
|
||||
|
||||
//Config config = JsonUtility.FromJson<Config>(File.ReadAllText(configFilePath));
|
||||
|
||||
Debug.Log(config.isContinuousLocomotion);
|
||||
Debug.Log(config.masterVolume);
|
||||
fileStream.Close();*/
|
||||
|
||||
return config;
|
||||
}
|
||||
@@ -106,15 +111,80 @@ public class ConfigManager : MonoBehaviour
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
|
||||
public float getMasterVolume()
|
||||
public float GetContinuousLocomotionSpeed()
|
||||
{
|
||||
|
||||
return currentConfig.masterVolume;
|
||||
return currentConfig.continuousLocomotionSpeed;
|
||||
}
|
||||
public void SetMasterVolume(float masterVolume)
|
||||
public void SetContinuousLocomotionSpeed(float continuousLocomotionSpeed)
|
||||
{
|
||||
currentConfig.masterVolume = masterVolume;
|
||||
currentConfig.continuousLocomotionSpeed = continuousLocomotionSpeed;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public float getVolumeMaster()
|
||||
{
|
||||
|
||||
return currentConfig.volumeMaster;
|
||||
}
|
||||
public void SetVolumeMaster(float masterVolume)
|
||||
{
|
||||
currentConfig.volumeMaster = masterVolume;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public float getVolumeAmbient()
|
||||
{
|
||||
|
||||
return currentConfig.volumeAmbient;
|
||||
}
|
||||
public void SetVolumeAmbient(float ambientVolume)
|
||||
{
|
||||
currentConfig.volumeAmbient = ambientVolume;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public float getVolumeMusic()
|
||||
{
|
||||
|
||||
return currentConfig.volumeMusic;
|
||||
}
|
||||
public void SetVolumeMusic(float musicVolume)
|
||||
{
|
||||
currentConfig.volumeMusic = musicVolume;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public float getVolumeSFX()
|
||||
{
|
||||
|
||||
return currentConfig.volumeSFX;
|
||||
}
|
||||
public void SetVolumeSFX(float sfxVolume)
|
||||
{
|
||||
currentConfig.volumeSFX = sfxVolume;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public float getVolumeUI()
|
||||
{
|
||||
|
||||
return currentConfig.volumeUI;
|
||||
}
|
||||
public void SetVolumeUI(float uiVolume)
|
||||
{
|
||||
currentConfig.volumeUI = uiVolume;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
|
||||
public float getVolumeVO()
|
||||
{
|
||||
|
||||
return currentConfig.volumeVO;
|
||||
}
|
||||
public void SetVolumeVO(float voVolume)
|
||||
{
|
||||
currentConfig.volumeVO = voVolume;
|
||||
SaveConfigToFile();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user