mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 22:27:45 +08:00

* Fixed a bug when editing a Text Field and the input string is `null`. Only affected Il2Cpp games, appeared in 1.8.0. * Added a menu page for editing the Explorer Settings in-game, called `Options`. * Added a new setting for default Items per Page Limit (for all "Pages" in Explorer).
66 lines
1.7 KiB
C#
66 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 int Default_Page_Limit = 20;
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|