Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit df33042

Browse files
committed
Add config to change main navbar anchor
1 parent 5af9d31 commit df33042

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

src/Core/Config/ConfigManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static class ConfigManager
1717
public static ConfigHandler Handler { get; private set; }
1818

1919
public static ConfigElement<KeyCode> Master_Toggle;
20+
public static ConfigElement<UIManager.VerticalAnchor> Main_Navbar_Anchor;
2021
public static ConfigElement<bool> Force_Unlock_Mouse;
2122
public static ConfigElement<KeyCode> Force_Unlock_Toggle;
2223
public static ConfigElement<bool> Aggressive_Mouse_Unlock;
@@ -75,6 +76,10 @@ private static void CreateConfigElements()
7576
"The key to enable or disable UnityExplorer's menu and features.",
7677
KeyCode.F7);
7778

79+
Main_Navbar_Anchor = new ConfigElement<UIManager.VerticalAnchor>("Main Navbar Anchor",
80+
"The vertical anchor of the main UnityExplorer Navbar, in case you want to move it.",
81+
UIManager.VerticalAnchor.Top);
82+
7883
Hide_On_Startup = new ConfigElement<bool>("Hide On Startup",
7984
"Should UnityExplorer be hidden on startup?",
8085
false);

src/UI/UIManager.cs

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,35 @@ public enum Panels
3131
MouseInspector
3232
}
3333

34+
public enum VerticalAnchor
35+
{
36+
Top,
37+
Bottom
38+
}
39+
3440
public static bool Initializing { get; private set; } = true;
3541

42+
private static readonly Dictionary<Panels, UIPanel> UIPanels = new Dictionary<Panels, UIPanel>();
43+
44+
public static VerticalAnchor NavbarAnchor = VerticalAnchor.Top;
45+
46+
// References
3647
public static GameObject CanvasRoot { get; private set; }
3748
public static Canvas Canvas { get; private set; }
3849
public static EventSystem EventSys { get; private set; }
3950

4051
internal static GameObject PoolHolder { get; private set; }
4152

42-
// panels
4353
internal static GameObject PanelHolder { get; private set; }
44-
private static readonly Dictionary<Panels, UIPanel> UIPanels = new Dictionary<Panels, UIPanel>();
4554

46-
// assets
4755
internal static Font ConsoleFont { get; private set; }
4856
internal static Shader BackupShader { get; private set; }
4957

50-
// Main Navbar UI
5158
public static RectTransform NavBarRect;
5259
public static GameObject NavbarButtonHolder;
5360
public static Dropdown MouseInspectDropdown;
5461

62+
// defaults
5563
internal static readonly Color enabledButtonColor = new Color(0.2f, 0.4f, 0.28f);
5664
internal static readonly Color disabledButtonColor = new Color(0.25f, 0.25f, 0.25f);
5765

@@ -140,6 +148,7 @@ public static void Update()
140148

141149
UIPanel.UpdateFocus();
142150
PanelDragger.UpdateInstances();
151+
InputFieldRef.UpdateInstances();
143152
UIBehaviourModel.UpdateInstances();
144153
}
145154

@@ -212,16 +221,41 @@ private static void CreateRootCanvas()
212221
PanelHolder.transform.SetAsFirstSibling();
213222
}
214223

224+
public static void SetNavBarAnchor()
225+
{
226+
switch (NavbarAnchor)
227+
{
228+
case VerticalAnchor.Top:
229+
NavBarRect.anchorMin = new Vector2(0.5f, 1f);
230+
NavBarRect.anchorMax = new Vector2(0.5f, 1f);
231+
NavBarRect.anchoredPosition = new Vector2(NavBarRect.anchoredPosition.x, 0);
232+
NavBarRect.sizeDelta = new Vector2(900f, 35f);
233+
break;
234+
235+
case VerticalAnchor.Bottom:
236+
NavBarRect.anchorMin = new Vector2(0.5f, 0f);
237+
NavBarRect.anchorMax = new Vector2(0.5f, 0f);
238+
NavBarRect.anchoredPosition = new Vector2(NavBarRect.anchoredPosition.x, 35);
239+
NavBarRect.sizeDelta = new Vector2(900f, 35f);
240+
break;
241+
}
242+
}
243+
215244
private static void CreateTopNavBar()
216245
{
217246
var navbarPanel = UIFactory.CreateUIObject("MainNavbar", CanvasRoot);
218247
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(navbarPanel, false, true, true, true, 5, 4, 4, 4, 4, TextAnchor.MiddleCenter);
219248
navbarPanel.AddComponent<Image>().color = new Color(0.1f, 0.1f, 0.1f);
220249
NavBarRect = navbarPanel.GetComponent<RectTransform>();
221250
NavBarRect.pivot = new Vector2(0.5f, 1f);
222-
NavBarRect.anchorMin = new Vector2(0.5f, 1f);
223-
NavBarRect.anchorMax = new Vector2(0.5f, 1f);
224-
NavBarRect.sizeDelta = new Vector2(900f, 35f);
251+
252+
NavbarAnchor = ConfigManager.Main_Navbar_Anchor.Value;
253+
SetNavBarAnchor();
254+
ConfigManager.Main_Navbar_Anchor.OnValueChanged += (VerticalAnchor val) =>
255+
{
256+
NavbarAnchor = val;
257+
SetNavBarAnchor();
258+
};
225259

226260
// UnityExplorer title
227261

0 commit comments

Comments
 (0)