mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-15 22:07:48 +08:00

* Added support for games which use the new InputSystem module and have disabled LegacyInputModule
65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
using System.IO;
|
|
using System.Xml.Serialization;
|
|
using UnityEngine;
|
|
|
|
namespace Explorer
|
|
{
|
|
public class ModConfig
|
|
{
|
|
[XmlIgnore] public static readonly XmlSerializer Serializer = new XmlSerializer(typeof(ModConfig));
|
|
|
|
[XmlIgnore] private const string EXPLORER_FOLDER = @"Mods\Explorer";
|
|
[XmlIgnore] private const string SETTINGS_PATH = EXPLORER_FOLDER + @"\config.xml";
|
|
|
|
[XmlIgnore] public static ModConfig Instance;
|
|
|
|
public KeyCode Main_Menu_Toggle = KeyCode.F7;
|
|
public Vector2 Default_Window_Size = new Vector2(550, 700);
|
|
|
|
public static void OnLoad()
|
|
{
|
|
if (!Directory.Exists(EXPLORER_FOLDER))
|
|
{
|
|
Directory.CreateDirectory(EXPLORER_FOLDER);
|
|
}
|
|
|
|
if (LoadSettings()) return;
|
|
|
|
Instance = new ModConfig();
|
|
SaveSettings();
|
|
}
|
|
|
|
// returns true if settings successfully loaded
|
|
public static bool LoadSettings()
|
|
{
|
|
if (!File.Exists(SETTINGS_PATH))
|
|
return false;
|
|
|
|
try
|
|
{
|
|
using (var file = File.OpenRead(SETTINGS_PATH))
|
|
{
|
|
Instance = (ModConfig)Serializer.Deserialize(file);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return Instance != null;
|
|
}
|
|
|
|
public static void SaveSettings()
|
|
{
|
|
if (File.Exists(SETTINGS_PATH))
|
|
File.Delete(SETTINGS_PATH);
|
|
|
|
using (var file = File.Create(SETTINGS_PATH))
|
|
{
|
|
Serializer.Serialize(file, Instance);
|
|
}
|
|
}
|
|
}
|
|
}
|