mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-15 07:56:41 +08:00
1.6.8
* Added a ModConfig, allowing you to define the main menu toggle keybind and the default window size (so far). * Made the parsing of arguments more intelligent, should now behave as expected for null or empty arguments.
This commit is contained in:
62
src/Config/ModConfig.cs
Normal file
62
src/Config/ModConfig.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
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\CppExplorer";
|
||||
[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 (File.Exists(SETTINGS_PATH))
|
||||
{
|
||||
LoadSettings(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Instance = new ModConfig();
|
||||
SaveSettings(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadSettings(bool checkExist = true)
|
||||
{
|
||||
if (checkExist && !File.Exists(SETTINGS_PATH))
|
||||
return;
|
||||
|
||||
var file = File.OpenRead(SETTINGS_PATH);
|
||||
Instance = (ModConfig)Serializer.Deserialize(file);
|
||||
file.Close();
|
||||
}
|
||||
|
||||
public static void SaveSettings(bool checkExist = true)
|
||||
{
|
||||
if (checkExist && File.Exists(SETTINGS_PATH))
|
||||
File.Delete(SETTINGS_PATH);
|
||||
|
||||
FileStream file = File.Create(SETTINGS_PATH);
|
||||
Serializer.Serialize(file, Instance);
|
||||
file.Close();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user