49 lines
1.9 KiB
C#
49 lines
1.9 KiB
C#
using UnityEngine;
|
|
using System.IO;
|
|
using System;
|
|
using System.Xml.Serialization;
|
|
|
|
namespace NeonTea.Quakeball {
|
|
/// <summary>Container for user-selected options.</summary>
|
|
[XmlRootAttribute("Options")]
|
|
public class OptionsData {
|
|
// DO NOT REMOVE OR CHANGE EXISTING FIELDS AFTER RELEASE TO AVOID BREAKING EXISTING CONFIGURATIONS
|
|
// New fields are fine though, the defaults will be used.
|
|
public bool InvertVerticalLook = false;
|
|
public float LookSensitivity = 0.1f;
|
|
}
|
|
|
|
/// <summary>A collection of functions to access user-specific configuration.</summary>
|
|
public static class Options {
|
|
private static string OptionsDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Quakeball");
|
|
private static string OptionsPath = Path.Combine(OptionsDirectory, "Config.xml");
|
|
private static OptionsData Singleton = Load();
|
|
|
|
public static OptionsData Get() {
|
|
return Singleton;
|
|
}
|
|
|
|
public static void Save(OptionsData options) {
|
|
XmlSerializer Serializer = new XmlSerializer(typeof(OptionsData));
|
|
Directory.CreateDirectory(OptionsDirectory);
|
|
FileStream OptionsFile = File.Create(OptionsPath);
|
|
Serializer.Serialize(OptionsFile, options);
|
|
OptionsFile.Close();
|
|
}
|
|
|
|
public static OptionsData Load() {
|
|
try {
|
|
XmlSerializer Serializer = new XmlSerializer(typeof(OptionsData));
|
|
FileStream OptionsFile = File.OpenRead(OptionsPath);
|
|
OptionsData Options = (OptionsData)Serializer.Deserialize(OptionsFile);
|
|
OptionsFile.Close();
|
|
return Options;
|
|
} catch (FileLoadException) {
|
|
} catch (Exception ex) {
|
|
Debug.LogWarning(ex);
|
|
}
|
|
return new OptionsData();
|
|
}
|
|
}
|
|
}
|