mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-04 20:42:22 +08:00
69 lines
2.0 KiB
C#
69 lines
2.0 KiB
C#
![]() |
#if BIE
|
|||
|
using BepInEx.Configuration;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using UnityExplorer.Core.Config;
|
|||
|
|
|||
|
namespace UnityExplorer.Loader.BIE
|
|||
|
{
|
|||
|
public class BepInExConfigHandler : IConfigHandler
|
|||
|
{
|
|||
|
private ConfigFile Config => ExplorerBepInPlugin.Instance.Config;
|
|||
|
|
|||
|
private const string CTG_NAME = "UnityExplorer";
|
|||
|
|
|||
|
public void Init()
|
|||
|
{
|
|||
|
// Not necessary
|
|||
|
}
|
|||
|
|
|||
|
public void RegisterConfigElement<T>(ConfigElement<T> config)
|
|||
|
{
|
|||
|
var entry = Config.Bind(CTG_NAME, config.Name, config.Value, config.Description);
|
|||
|
|
|||
|
entry.SettingChanged += (object o, EventArgs e) =>
|
|||
|
{
|
|||
|
config.Value = entry.Value;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public T GetConfigValue<T>(ConfigElement<T> element)
|
|||
|
{
|
|||
|
if (Config.TryGetEntry(CTG_NAME, element.Name, out ConfigEntry<T> configEntry))
|
|||
|
return configEntry.Value;
|
|||
|
else
|
|||
|
throw new Exception("Could not get config entry '" + element.Name + "'");
|
|||
|
}
|
|||
|
|
|||
|
public void SetConfigValue<T>(ConfigElement<T> element, T value)
|
|||
|
{
|
|||
|
if (Config.TryGetEntry(CTG_NAME, element.Name, out ConfigEntry<T> configEntry))
|
|||
|
configEntry.Value = value;
|
|||
|
else
|
|||
|
ExplorerCore.Log("Could not get config entry '" + element.Name + "'");
|
|||
|
}
|
|||
|
|
|||
|
public void LoadConfig()
|
|||
|
{
|
|||
|
foreach (var entry in ConfigManager.ConfigElements)
|
|||
|
{
|
|||
|
var key = entry.Key;
|
|||
|
var def = new ConfigDefinition(CTG_NAME, key);
|
|||
|
if (Config.ContainsKey(def) && Config[def] is ConfigEntryBase configEntry)
|
|||
|
{
|
|||
|
var config = entry.Value;
|
|||
|
config.BoxedValue = configEntry.BoxedValue;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void SaveConfig()
|
|||
|
{
|
|||
|
// not required
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endif
|