public void UpdateFile(OptionsSerializer serializer) { options = serializer; TextWriter writer = new StreamWriter("Assets/option.json"); writer.Write(JsonUtility.ToJson(serializer)); writer.Close(); }
public static void deserialize(OptionsSerializer ser) { fullscreen = ser.fullscreen; resolutionIndex = ser.resolutionIndex; textureQuality = ser.textureQuality; antialiasing = ser.antialiasing; vSync = ser.vSync; musicVolume = ser.musicVolume; }
private void Start() { OptionsData data = OptionsSerializer.Load(); if (data != null) { generalVolumeSlider.value = data.generalVolume; musicVolumeSlider.value = data.musicVolume; effectsVolumeSlider.value = data.effectsVolume; } }
public void SaveOptions() { OptionsData data = new OptionsData { generalVolume = generalVolumeSlider.value, musicVolume = musicVolumeSlider.value, effectsVolume = effectsVolumeSlider.value }; OptionsSerializer.Save(data); }
public void SaveSettings() { // Create a new serializer version of Options and update so all variables are current. OptionsSerializer serializer = new OptionsSerializer(); serializer.Update(); string jsonData = JsonUtility.ToJson(serializer, true); File.WriteAllText(Application.persistentDataPath + "/gamesettings.json", jsonData); }
private void Start() { OptionsData data = OptionsSerializer.Load(); if (data != null) { SetGeneralVolume(data.generalVolume); SetMusicVolume(data.musicVolume); SetEffectsVolume(data.effectsVolume); } }
void Start() { // First, check for a custom graphics file. if (System.IO.File.Exists(Application.persistentDataPath + "/gamesettings.json")) { // A file exists, load the data from said file OptionsSerializer ser = new OptionsSerializer(); string jsonData = File.ReadAllText(Application.persistentDataPath + "/gamesettings.json"); ser = JsonUtility.FromJson <OptionsSerializer>(jsonData); Options.deserialize(ser); } else { // No file exists for user-defined graphics. Create one using the unity quality settings OptionsSerializer ser = new OptionsSerializer(); ser.fullscreen = Screen.fullScreen; ser.resolutionIndex = 0; ser.textureQuality = QualitySettings.masterTextureLimit; switch (QualitySettings.antiAliasing) { case 0: ser.antialiasing = 0; break; case 2: ser.antialiasing = 1; break; case 4: ser.antialiasing = 2; break; case 8: ser.antialiasing = 3; break; case 16: ser.antialiasing = 4; break; default: ser.antialiasing = 0; break; } ser.vSync = QualitySettings.vSyncCount; ser.musicVolume = 0.5f; string jsonData = JsonUtility.ToJson(ser, true); File.WriteAllText(Application.persistentDataPath + "/gamesettings.json", jsonData); } }
private void EnsureSolutionOptionsFileCreated() { bool solutionConfigExists = File.Exists(_solutionConfigurationPath); if (!solutionConfigExists) { using (FileStream fstream = File.Open(_solutionConfigurationPath, FileMode.Create)) { OptionsSerializer serializer = new OptionsSerializer(); serializer.Serialize(fstream, OptionsProviderRegistry.CurrentOptions); fstream.Flush(); } } }
public override void Save(Options options) { _options = options; using (MemoryStream cloneStream = new MemoryStream()) using (FileStream fstream = new FileStream(_filePath, FileMode.Create, FileAccess.Write)) { OptionsSerializer serializer = new OptionsSerializer(); serializer.Serialize(cloneStream, options); cloneStream.Position = 0; cloneStream.CopyTo(fstream); cloneStream.Position = 0; _options = serializer.Deserialize(cloneStream); } }
internal static FormsConfig CreateFromXML(string xml) { FormsConfig config = null; if (!string.IsNullOrWhiteSpace(xml)) { try { config = OptionsSerializer.LoadXML <FormsConfig>(xml); } catch (Exception ex) { Loger.SendMess(ex, $"Ошибка загрузки параметров форм из строки"); xml = null; } } if (string.IsNullOrWhiteSpace(xml)) { config = new FormsConfig(); } return(config); }
public void LoadSettings() { // Load data OptionsSerializer serializer = new OptionsSerializer(); File.ReadAllText(Application.persistentDataPath + "/gamesettings.json"); serializer = JsonUtility.FromJson <OptionsSerializer>(File.ReadAllText(Application.persistentDataPath + "/gamesettings.json")); // Transfer data into static Options class Options.deserialize(serializer); // Update values musicSlider.value = Options.musicVolume; vSyncDropdown.value = Options.vSync; antialiasingDropdown.value = Options.antialiasing; textureDropdown.value = Options.textureQuality; resolutionDropdown.value = Options.resolutionIndex; fullscreenToggle.isOn = Options.fullscreen; Screen.fullScreen = Options.fullscreen; resolutionDropdown.RefreshShownValue(); }
public OptionsSerializer GetOptions() { OptionsSerializer optionResult = new OptionsSerializer(); try { TextReader reader; reader = new StreamReader("Assets/option.json"); string result = reader.ReadToEnd(); reader.Close(); optionResult = JsonUtility.FromJson <OptionsSerializer>(result); } catch (FileNotFoundException e) { TextWriter writer; writer = new StreamWriter("Assets/option.json"); writer.Write(JsonUtility.ToJson(optionResult)); writer.Close(); Debug.Log(e); } return(optionResult); }
/// <summary>Заполняет контейнер параметров форм из файла. Если файла нет - создает новый. /// </summary> /// <param name="fileName">имя файла, по умолчанию: Forms + имя приложения.xml</param> /// <returns>контейнер параметров форм</returns> internal static FormsConfig CreateFromFile(string fileName = "") { FormsConfig config = null; if (string.IsNullOrWhiteSpace(fileName)) { fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Forms" + Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName) + ".xml"); } try { if (!File.Exists(fileName)) { OptionsSerializer.Save(fileName, new FormsConfig()); } config = OptionsSerializer.Load <FormsConfig>(fileName); if (config != null) { config.fileName = fileName; } } catch (Exception ex) { Loger.SendMess(ex, $"Ошибка загрузки параметров форм из файла {fileName}"); } return(config); }
/// <summary>Запись контейнера в файл /// </summary> internal void Save() { OptionsSerializer.Save(fileName, this); }
static void Main() { foreach (var proc in Process.GetProcessesByName(PKStudioLauncherName)) { if (proc.Id != Process.GetCurrentProcess().Id) { return; } } var tool = string.Empty; var toolPath = string.Empty; var toolVersion = string.Empty; var pkPath = string.Empty; if (File.Exists(OptionsPath)) { var serializer = OptionsSerializer.BackState(OptionsPath); foreach (var option in serializer.SOptions) { var envOption = option as EnvironmentOption; if (envOption != null) { tool = EnvironmentOption.GetToolString(envOption.Tool); toolPath = envOption.Path; toolVersion = envOption.Version; } var verOption = option as PKVersionOption; if (verOption != null) { pkPath = verOption.PKVersion.Path; } } } var path = ""; var portingKitRegistryValue = Environment.GetEnvironmentVariable("SPOCLIENT"); var spoClientPath = ""; if (string.IsNullOrEmpty(portingKitRegistryValue) || !Directory.Exists(portingKitRegistryValue)) { portingKitRegistryValue = pkPath; } if (string.IsNullOrEmpty(portingKitRegistryValue) || !Directory.Exists(portingKitRegistryValue)) { portingKitRegistryValue = Helper.GetPortingKitRegistryValue("", "InstallRoot"); } if (!string.IsNullOrEmpty(portingKitRegistryValue) && Directory.Exists(portingKitRegistryValue)) { path = portingKitRegistryValue; } if (!Directory.Exists(path) || !Directory.Exists(path + @"\DeviceCode\Targets\")) { using (var of = new SetSPOForm()) { if (of.ShowDialog() != System.Windows.Forms.DialogResult.OK) { Console.WriteLine(@".NET Micro Framework Porting Kit directory was not found. Waiting for exit..."); Process.GetCurrentProcess().WaitForExit(); } else { if (Directory.Exists(path + @"\DeviceCode\Targets\")) { spoClientPath = of.Path; } else { Console.WriteLine(@".NET Micro Framework Porting Kit directory was not found. Waiting for exit..."); Process.GetCurrentProcess().WaitForExit(); } } } } else { Environment.SetEnvironmentVariable("SPOCLIENT", path); spoClientPath = path; } if (spoClientPath.Substring(spoClientPath.Length - 1, 1) != @"\") { spoClientPath += @"\"; } path = string.Format("{0}setenv_base.cmd {1} {2} {3}", spoClientPath, tool, toolVersion, toolPath); foreach (var proc in Process.GetProcessesByName("PKStudio")) { Console.WriteLine(@"Another running copy of PKStudio has been detected. Waiting for exit..."); proc.WaitForExit(); } if (File.Exists(PKStudioPath)) { var process = new Process(); var info = process.StartInfo; info.FileName = Environment.ExpandEnvironmentVariables("%comspec%"); info.RedirectStandardInput = true; info.UseShellExecute = false; info.WindowStyle = ProcessWindowStyle.Hidden; if (process.Start()) { process.StandardInput.WriteLine(path); process.StandardInput.WriteLine(PKStudioPath); } } else { Console.WriteLine(@"PKStudio executable not found."); } }
internal string GetXML() { return(OptionsSerializer.GetXML(this)); }
// Use this for initialization void Start() { options = GetOptions(); }