mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-01-06 01:23:31 +08:00
Save window size between launches
This commit is contained in:
parent
21408993c2
commit
9072b16c5a
@ -3,6 +3,7 @@ using System.IO;
|
||||
using UnityEngine;
|
||||
using IniParser;
|
||||
using IniParser.Parser;
|
||||
using UnityExplorer.UI;
|
||||
|
||||
namespace UnityExplorer.Config
|
||||
{
|
||||
@ -16,16 +17,20 @@ namespace UnityExplorer.Config
|
||||
static ExplorerConfig()
|
||||
{
|
||||
_parser.Configuration.CommentString = "#";
|
||||
|
||||
PanelDragger.OnFinishResize += PanelDragger_OnFinishResize;
|
||||
}
|
||||
|
||||
// Actual configs
|
||||
public KeyCode Main_Menu_Toggle = KeyCode.F7;
|
||||
public bool Force_Unlock_Mouse = true;
|
||||
public int Default_Page_Limit = 25;
|
||||
public string Default_Output_Path = ExplorerCore.ExplorerFolder + @"\Output";
|
||||
public string Default_Output_Path = Path.Combine(ExplorerCore.ExplorerFolder, "Output");
|
||||
public bool Log_Unity_Debug = false;
|
||||
public bool Hide_On_Startup = false;
|
||||
//public bool Save_Logs_To_Disk = true;
|
||||
public string Window_Anchors = DEFAULT_WINDOW_ANCHORS;
|
||||
|
||||
private const string DEFAULT_WINDOW_ANCHORS = "0.25,0.1,0.78,0.95";
|
||||
|
||||
public static event Action OnConfigChanged;
|
||||
|
||||
@ -75,9 +80,9 @@ namespace UnityExplorer.Config
|
||||
case nameof(Hide_On_Startup):
|
||||
Instance.Hide_On_Startup = bool.Parse(config.Value);
|
||||
break;
|
||||
//case nameof(Save_Logs_To_Disk):
|
||||
// Instance.Save_Logs_To_Disk = bool.Parse(config.Value);
|
||||
// break;
|
||||
case nameof(Window_Anchors):
|
||||
Instance.Window_Anchors = config.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,12 +102,52 @@ namespace UnityExplorer.Config
|
||||
sec.AddKey(nameof(Log_Unity_Debug), Instance.Log_Unity_Debug.ToString());
|
||||
sec.AddKey(nameof(Default_Output_Path), Instance.Default_Output_Path);
|
||||
sec.AddKey(nameof(Hide_On_Startup), Instance.Hide_On_Startup.ToString());
|
||||
//sec.AddKey("Save_Logs_To_Disk", Instance.Save_Logs_To_Disk.ToString());
|
||||
sec.AddKey(nameof(Window_Anchors), GetWindowAnchorsString());
|
||||
|
||||
if (!Directory.Exists(ExplorerCore.Loader.ConfigFolder))
|
||||
Directory.CreateDirectory(ExplorerCore.Loader.ConfigFolder);
|
||||
|
||||
File.WriteAllText(INI_PATH, data.ToString());
|
||||
}
|
||||
|
||||
// ============ Window Anchors specific stuff ============== //
|
||||
|
||||
private static void PanelDragger_OnFinishResize()
|
||||
{
|
||||
Instance.Window_Anchors = GetWindowAnchorsString();
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
internal Vector4 GetWindowAnchorsVector()
|
||||
{
|
||||
try
|
||||
{
|
||||
var split = Window_Anchors.Split(',');
|
||||
Vector4 ret = Vector4.zero;
|
||||
ret.x = float.Parse(split[0]);
|
||||
ret.y = float.Parse(split[1]);
|
||||
ret.z = float.Parse(split[2]);
|
||||
ret.w = float.Parse(split[3]);
|
||||
return ret;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Window_Anchors = DEFAULT_WINDOW_ANCHORS;
|
||||
return GetWindowAnchorsVector();
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetWindowAnchorsString()
|
||||
{
|
||||
try
|
||||
{
|
||||
var rect = PanelDragger.Instance.Panel;
|
||||
return $"{rect.anchorMin.x},{rect.anchorMin.y},{rect.anchorMax.x},{rect.anchorMax.y}";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return DEFAULT_WINDOW_ANCHORS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,8 +155,11 @@ namespace UnityExplorer.UI
|
||||
MainPanel = UIFactory.CreatePanel(UIManager.CanvasRoot, "MainMenu", out GameObject content);
|
||||
|
||||
RectTransform panelRect = MainPanel.GetComponent<RectTransform>();
|
||||
panelRect.anchorMin = new Vector2(0.25f, 0.1f);
|
||||
panelRect.anchorMax = new Vector2(0.78f, 0.95f);
|
||||
//panelRect.anchorMin = new Vector2(0.25f, 0.1f);
|
||||
//panelRect.anchorMax = new Vector2(0.78f, 0.95f);
|
||||
var anchors = ExplorerConfig.Instance.GetWindowAnchorsVector();
|
||||
panelRect.anchorMin = new Vector2(anchors.x, anchors.y);
|
||||
panelRect.anchorMax = new Vector2(anchors.z, anchors.w);
|
||||
|
||||
MainPanel.AddComponent<Mask>();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user