mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 22:27:45 +08:00
Add wrapper to handle LemonAction issue
This commit is contained in:
parent
9ce6508828
commit
e2c1c186c3
@ -34,17 +34,34 @@ namespace UnityExplorer.Loader.ML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void RegisterConfigElement<T>(ConfigElement<T> config)
|
// This wrapper exists to handle the arbitrary "LemonAction" delegates which ML now uses in 0.4.4+.
|
||||||
|
// Reflection is required since the delegate type changed between 0.4.3 and 0.4.4.
|
||||||
|
// A wrapper class is required to link the MelonPreferences_Entry and the delegate instance.
|
||||||
|
public class EntryDelegateWrapper<T>
|
||||||
{
|
{
|
||||||
var entry = prefCategory.CreateEntry(config.Name, config.Value, null, config.Description, config.IsInternal, false);
|
public MelonPreferences_Entry<T> entry;
|
||||||
|
public ConfigElement<T> config;
|
||||||
entry.OnValueChangedUntyped += () =>
|
|
||||||
|
public EntryDelegateWrapper(MelonPreferences_Entry<T> entry, ConfigElement<T> config)
|
||||||
|
{
|
||||||
|
this.entry = entry;
|
||||||
|
this.config = config;
|
||||||
|
var evt = entry.GetType().GetEvent("OnValueChangedUntyped");
|
||||||
|
evt.AddEventHandler(entry, Delegate.CreateDelegate(evt.EventHandlerType, this, GetType().GetMethod("OnChanged")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnChanged()
|
||||||
{
|
{
|
||||||
if ((entry.Value == null && config.Value == null) || config.Value.Equals(entry.Value))
|
if ((entry.Value == null && config.Value == null) || config.Value.Equals(entry.Value))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
config.Value = entry.Value;
|
config.Value = entry.Value;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void RegisterConfigElement<T>(ConfigElement<T> config)
|
||||||
|
{
|
||||||
|
var entry = prefCategory.CreateEntry(config.Name, config.Value, null, config.Description, config.IsInternal, false);
|
||||||
|
new EntryDelegateWrapper<T>(entry, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetConfigValue<T>(ConfigElement<T> config, T value)
|
public override void SetConfigValue<T>(ConfigElement<T> config, T value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user