More progress, and change Aggressive Mouse Unlock behaviour

This commit is contained in:
Sinai
2021-04-29 21:01:08 +10:00
parent a2a2b09d33
commit dba9bdbdc2
22 changed files with 365 additions and 233 deletions

View File

@ -29,10 +29,8 @@ namespace UnityExplorer.Core.Config
// internal configs
internal static InternalConfigHandler InternalHandler { get; private set; }
public static ConfigElement<string> SceneExplorerData;
public static ConfigElement<string> GameObjectInspectorData;
public static ConfigElement<string> MainWindowData;
public static ConfigElement<string> DebugConsoleData;
public static ConfigElement<string> ObjectExplorerData;
public static ConfigElement<string> InspectorData;
internal static readonly Dictionary<string, IConfigElement> ConfigElements = new Dictionary<string, IConfigElement>();
internal static readonly Dictionary<string, IConfigElement> InternalConfigs = new Dictionary<string, IConfigElement>();
@ -86,13 +84,9 @@ namespace UnityExplorer.Core.Config
KeyCode.None);
Aggressive_Force_Unlock = new ConfigElement<bool>("Aggressive Mouse Unlock",
"Use Camera.onPostRender callback to aggressively force the Mouse to be unlocked (requires game restart).",
"Use WaitForEndOfFrame to aggressively force the Mouse to be unlocked (requires game restart).",
false);
//Default_Tab = new ConfigElement<MenuPages>("Default Tab",
// "The default menu page when starting the game.",
// MenuPages.Home);
Log_Unity_Debug = new ConfigElement<bool>("Log Unity Debug",
"Should UnityEngine.Debug.Log messages be printed to UnityExplorer's log?",
false);
@ -111,10 +105,8 @@ namespace UnityExplorer.Core.Config
// Internal configs
SceneExplorerData = new ConfigElement<string>("SceneExplorer", "", "", true);
GameObjectInspectorData = new ConfigElement<string>("GameObjectInspector", "", "", true);
MainWindowData = new ConfigElement<string>("MainWindow", "", "", true);
DebugConsoleData = new ConfigElement<string>("DebugConsole", "", "", true);
ObjectExplorerData = new ConfigElement<string>("ObjectExplorer", "", "", true);
InspectorData = new ConfigElement<string>("Inspector", "", "", true);
}
}
}

View File

@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityExplorer.UI;
namespace UnityExplorer.Core.Config
{
@ -33,8 +34,7 @@ namespace UnityExplorer.Core.Config
public override void SetConfigValue<T>(ConfigElement<T> element, T value)
{
// Not necessary, just save.
SaveConfig();
// Not necessary
}
public override T GetConfigValue<T>(ConfigElement<T> element)
@ -43,10 +43,17 @@ namespace UnityExplorer.Core.Config
return element.Value;
}
public override void OnAnyConfigChanged()
{
SaveConfig();
}
public bool TryLoadConfig()
{
try
{
ExplorerCore.Log("Loading internal data");
if (!File.Exists(INI_PATH))
return false;
@ -60,33 +67,22 @@ namespace UnityExplorer.Core.Config
configElement.BoxedValue = StringToConfigValue(config.Value, configElement.ElementType);
}
ExplorerCore.Log("Loaded");
return true;
}
catch
catch (Exception ex)
{
ExplorerCore.LogWarning("Error loading internal data: " + ex.ToString());
return false;
}
}
public object StringToConfigValue(string value, Type elementType)
{
if (elementType.IsEnum)
return Enum.Parse(elementType, value);
else if (elementType == typeof(bool))
return bool.Parse(value);
else if (elementType == typeof(int))
return int.Parse(value);
else
return value;
}
public override void OnAnyConfigChanged()
{
SaveConfig();
}
public override void SaveConfig()
{
if (UIManager.Initializing)
return;
var data = new IniParser.Model.IniData();
data.Sections.AddSection("Config");
@ -100,5 +96,17 @@ namespace UnityExplorer.Core.Config
File.WriteAllText(INI_PATH, data.ToString());
}
public object StringToConfigValue(string value, Type elementType)
{
if (elementType.IsEnum)
return Enum.Parse(elementType, value);
else if (elementType == typeof(bool))
return bool.Parse(value);
else if (elementType == typeof(int))
return int.Parse(value);
else
return value;
}
}
}