mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 22:27:45 +08:00
Cleanup
This commit is contained in:
parent
ca27d2b20f
commit
fa3a436037
@ -166,15 +166,17 @@ namespace UnityExplorer.Core.Input
|
|||||||
|
|
||||||
PrefixMethod(typeof(EventSystem),
|
PrefixMethod(typeof(EventSystem),
|
||||||
"SetSelectedGameObject",
|
"SetSelectedGameObject",
|
||||||
new Type[] { typeof(GameObject), typeof(BaseEventData) },
|
|
||||||
new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_EventSystem_SetSelectedGameObject))),
|
|
||||||
new Type[] { typeof(GameObject), typeof(BaseEventData), typeof(int) });
|
|
||||||
// some games use a modified version of uGUI that includes this extra int argument on this method.
|
// some games use a modified version of uGUI that includes this extra int argument on this method.
|
||||||
|
new Type[] { typeof(GameObject), typeof(BaseEventData), typeof(int) },
|
||||||
|
new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_EventSystem_SetSelectedGameObject))),
|
||||||
|
// most games use these arguments, we'll use them as our "backup".
|
||||||
|
new Type[] { typeof(GameObject), typeof(BaseEventData) });
|
||||||
|
|
||||||
PrefixMethod(typeof(PointerInputModule),
|
//// Not sure if this one is needed.
|
||||||
"ClearSelection",
|
//PrefixMethod(typeof(PointerInputModule),
|
||||||
new Type[] { },
|
// "ClearSelection",
|
||||||
new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_PointerInputModule_ClearSelection))));
|
// new Type[0],
|
||||||
|
// new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_PointerInputModule_ClearSelection))));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -222,11 +224,6 @@ namespace UnityExplorer.Core.Input
|
|||||||
|
|
||||||
// Prevent setting non-UnityExplorer objects as selected when menu is open
|
// Prevent setting non-UnityExplorer objects as selected when menu is open
|
||||||
|
|
||||||
public static bool Prefix_PointerInputModule_ClearSelection()
|
|
||||||
{
|
|
||||||
return !(UIManager.ShowMenu && UIManager.CanvasRoot);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool Prefix_EventSystem_SetSelectedGameObject(GameObject __0)
|
public static bool Prefix_EventSystem_SetSelectedGameObject(GameObject __0)
|
||||||
{
|
{
|
||||||
if (!UIManager.ShowMenu || !UIManager.CanvasRoot)
|
if (!UIManager.ShowMenu || !UIManager.CanvasRoot)
|
||||||
@ -235,6 +232,11 @@ namespace UnityExplorer.Core.Input
|
|||||||
return __0 && __0.transform.root.gameObject.GetInstanceID() == UIManager.CanvasRoot.GetInstanceID();
|
return __0 && __0.transform.root.gameObject.GetInstanceID() == UIManager.CanvasRoot.GetInstanceID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//public static bool Prefix_PointerInputModule_ClearSelection()
|
||||||
|
//{
|
||||||
|
// return !(UIManager.ShowMenu && UIManager.CanvasRoot);
|
||||||
|
//}
|
||||||
|
|
||||||
// Force EventSystem.current to be UnityExplorer's when menu is open
|
// Force EventSystem.current to be UnityExplorer's when menu is open
|
||||||
|
|
||||||
public static void Prefix_EventSystem_set_current(ref EventSystem value)
|
public static void Prefix_EventSystem_set_current(ref EventSystem value)
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
#if ML
|
#if ML
|
||||||
|
|
||||||
#if !ML_LEGACY // ML 0.3.1+ config handler
|
|
||||||
|
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -77,130 +74,4 @@ namespace UnityExplorer.Loader.ML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // ML 0.3.0 config handler
|
|
||||||
|
|
||||||
using MelonLoader;
|
|
||||||
using MelonLoader.Tomlyn.Model;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityExplorer.Core;
|
|
||||||
using UnityExplorer.Core.Config;
|
|
||||||
|
|
||||||
namespace UnityExplorer.Loader.ML
|
|
||||||
{
|
|
||||||
public class MelonLoaderConfigHandler : ConfigHandler
|
|
||||||
{
|
|
||||||
internal const string CTG_NAME = "UnityExplorer";
|
|
||||||
|
|
||||||
internal MelonPreferences_Category prefCategory;
|
|
||||||
|
|
||||||
public override void Init()
|
|
||||||
{
|
|
||||||
prefCategory = MelonPreferences.CreateCategory(CTG_NAME, $"{CTG_NAME} Settings");
|
|
||||||
|
|
||||||
try { MelonPreferences.Mapper.RegisterMapper(KeycodeReader, KeycodeWriter); } catch { }
|
|
||||||
try { MelonPreferences.Mapper.RegisterMapper(AnchorReader, AnchorWriter); } catch { }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void LoadConfig()
|
|
||||||
{
|
|
||||||
foreach (var entry in ConfigManager.ConfigElements)
|
|
||||||
{
|
|
||||||
var key = entry.Key;
|
|
||||||
if (prefCategory.GetEntry(key) is MelonPreferences_Entry)
|
|
||||||
{
|
|
||||||
var config = entry.Value;
|
|
||||||
config.BoxedValue = config.GetLoaderConfigValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void RegisterConfigElement<T>(ConfigElement<T> config)
|
|
||||||
{
|
|
||||||
var entry = prefCategory.CreateEntry(config.Name, config.Value, null, config.IsInternal) as MelonPreferences_Entry<T>;
|
|
||||||
|
|
||||||
entry.OnValueChangedUntyped += () =>
|
|
||||||
{
|
|
||||||
if ((entry.Value == null && config.Value == null) || config.Value.Equals(entry.Value))
|
|
||||||
return;
|
|
||||||
|
|
||||||
config.Value = entry.Value;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SetConfigValue<T>(ConfigElement<T> config, T value)
|
|
||||||
{
|
|
||||||
if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
|
|
||||||
{
|
|
||||||
entry.Value = value;
|
|
||||||
entry.Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override T GetConfigValue<T>(ConfigElement<T> config)
|
|
||||||
{
|
|
||||||
if (prefCategory.GetEntry<T>(config.Name) is MelonPreferences_Entry<T> entry)
|
|
||||||
return entry.Value;
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnAnyConfigChanged()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SaveConfig()
|
|
||||||
{
|
|
||||||
MelonPreferences.Save();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enum config handlers
|
|
||||||
|
|
||||||
public static KeyCode KeycodeReader(TomlObject value)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
KeyCode kc = (KeyCode)Enum.Parse(typeof(KeyCode), (value as TomlString).Value);
|
|
||||||
|
|
||||||
if (kc == default)
|
|
||||||
throw new Exception();
|
|
||||||
|
|
||||||
return kc;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return KeyCode.F7;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TomlObject KeycodeWriter(KeyCode value)
|
|
||||||
{
|
|
||||||
return MelonPreferences.Mapper.ToToml(value.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UI.UIManager.VerticalAnchor AnchorReader(TomlObject value)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return (UI.UIManager.VerticalAnchor)Enum.Parse(typeof(UI.UIManager.VerticalAnchor), (value as TomlString).Value);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return UI.UIManager.VerticalAnchor.Top;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TomlObject AnchorWriter(UI.UIManager.VerticalAnchor anchor)
|
|
||||||
{
|
|
||||||
return MelonPreferences.Mapper.ToToml(anchor.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user