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

Commit 0555a64

Browse files
committed
3.3.0 rewrite
* Huge restructure/rewrite. No real changes to any functionality, just a cleaner and more manageable project.
1 parent f66a04c commit 0555a64

File tree

90 files changed

+4197
-5648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+4197
-5648
lines changed

src/Core/CSharp/ScriptInteraction.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
using System;
22
using Mono.CSharp;
3-
using UnityExplorer.UI;
4-
using UnityExplorer.UI.Main;
5-
using UnityExplorer.Core.Inspectors;
6-
using UnityExplorer.UI.Main.CSConsole;
73
using System.Collections;
84
using UnityEngine;
95
using System.Collections.Generic;
106
using System.Linq;
117
using UnityExplorer.Core.Runtime;
8+
using UnityExplorer.UI.Main.CSConsole;
9+
using UnityExplorer.UI.Main.Home;
1210

1311
namespace UnityExplorer.Core.CSharp
1412
{

src/Core/CSharp/Suggestion.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Reflection;
55
using UnityEngine;
66
using UnityExplorer.Core;
7-
using UnityExplorer.Core.Unity;
87
using UnityExplorer.UI.Main.CSConsole;
98

109
namespace UnityExplorer.Core.CSharp
@@ -47,8 +46,8 @@ private Color GetTextColor()
4746

4847
// ~~~~ Static ~~~~
4948

50-
public static HashSet<string> Namespaces => m_namspaces ?? GetNamespaces();
51-
private static HashSet<string> m_namspaces;
49+
public static HashSet<string> Namespaces => m_namespaces ?? GetNamespaces();
50+
private static HashSet<string> m_namespaces;
5251

5352
public static HashSet<string> Keywords => m_keywords ?? (m_keywords = new HashSet<string>(CSLexerHighlighter.validKeywordMatcher.Keywords));
5453
private static HashSet<string> m_keywords;
@@ -63,7 +62,7 @@ private static HashSet<string> GetNamespaces()
6362
.Where(x => x.IsPublic && !string.IsNullOrEmpty(x.Namespace))
6463
.Select(x => x.Namespace));
6564

66-
return m_namspaces = set;
65+
return m_namespaces = set;
6766

6867
IEnumerable<Type> GetTypes(Assembly asm) => asm.TryGetTypes();
6968
}

src/Core/Config/ConfigElement.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace UnityExplorer.Core.Config
7+
{
8+
public class ConfigElement<T> : IConfigElement
9+
{
10+
public string Name { get; }
11+
public string Description { get; }
12+
13+
public bool IsInternal { get; }
14+
public Type ElementType => typeof(T);
15+
16+
public Action<T> OnValueChanged;
17+
public Action OnValueChangedNotify { get; set; }
18+
19+
public T Value
20+
{
21+
get => m_value;
22+
set => SetValue(value);
23+
}
24+
private T m_value;
25+
26+
object IConfigElement.BoxedValue
27+
{
28+
get => m_value;
29+
set => SetValue((T)value);
30+
}
31+
32+
public ConfigElement(string name, string description, T defaultValue, bool isInternal)
33+
{
34+
Name = name;
35+
Description = description;
36+
37+
m_value = defaultValue;
38+
39+
IsInternal = isInternal;
40+
41+
ConfigManager.RegisterConfigElement(this);
42+
}
43+
44+
private void SetValue(T value)
45+
{
46+
if ((m_value == null && value == null) || m_value.Equals(value))
47+
return;
48+
49+
m_value = value;
50+
51+
ConfigManager.Handler.SetConfigValue(this, value);
52+
53+
OnValueChanged?.Invoke(value);
54+
OnValueChangedNotify?.Invoke();
55+
}
56+
57+
object IConfigElement.GetLoaderConfigValue() => GetLoaderConfigValue();
58+
59+
public T GetLoaderConfigValue()
60+
{
61+
return ConfigManager.Handler.GetConfigValue(this);
62+
}
63+
}
64+
}

src/Core/Config/ConfigManager.cs

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using UnityEngine;
8+
using UnityExplorer.UI.Main;
9+
using UnityExplorer.UI.Main.Home;
10+
11+
namespace UnityExplorer.Core.Config
12+
{
13+
public static class ConfigManager
14+
{
15+
// Each Loader has its own ConfigHandler.
16+
// See the UnityExplorer.Loader namespace for the implementations.
17+
public static IConfigHandler Handler { get; private set; }
18+
19+
public static ConfigElement<KeyCode> Main_Menu_Toggle;
20+
public static ConfigElement<int> Default_Page_Limit;
21+
public static ConfigElement<string> Default_Output_Path;
22+
public static ConfigElement<bool> Log_Unity_Debug;
23+
public static ConfigElement<bool> Hide_On_Startup;
24+
public static ConfigElement<string> Last_Window_Anchors;
25+
public static ConfigElement<int> Last_Active_Tab;
26+
public static ConfigElement<bool> Last_DebugConsole_State;
27+
public static ConfigElement<bool> Last_SceneExplorer_State;
28+
29+
internal static readonly Dictionary<string, IConfigElement> ConfigElements = new Dictionary<string, IConfigElement>();
30+
31+
public static void Init(IConfigHandler configHandler)
32+
{
33+
Handler = configHandler;
34+
Handler.Init();
35+
36+
CreateConfigElements();
37+
38+
Handler.LoadConfig();
39+
40+
SceneExplorer.OnToggleShow += SceneExplorer_OnToggleShow;
41+
PanelDragger.OnFinishResize += PanelDragger_OnFinishResize;
42+
MainMenu.OnActiveTabChanged += MainMenu_OnActiveTabChanged;
43+
DebugConsole.OnToggleShow += DebugConsole_OnToggleShow;
44+
}
45+
46+
internal static void RegisterConfigElement<T>(ConfigElement<T> configElement)
47+
{
48+
Handler.RegisterConfigElement(configElement);
49+
ConfigElements.Add(configElement.Name, configElement);
50+
}
51+
52+
private static void CreateConfigElements()
53+
{
54+
Main_Menu_Toggle = new ConfigElement<KeyCode>("Main Menu Toggle",
55+
"The UnityEngine.KeyCode to toggle the UnityExplorer Menu.",
56+
KeyCode.F7,
57+
false);
58+
59+
Default_Page_Limit = new ConfigElement<int>("Default Page Limit",
60+
"The default maximum number of elements per 'page' in UnityExplorer.",
61+
25,
62+
false);
63+
64+
Default_Output_Path = new ConfigElement<string>("Default Output Path",
65+
"The default output path when exporting things from UnityExplorer.",
66+
Path.Combine(ExplorerCore.Loader.ExplorerFolder, "Output"),
67+
false);
68+
69+
Log_Unity_Debug = new ConfigElement<bool>("Log Unity Debug",
70+
"Should UnityEngine.Debug.Log messages be printed to UnityExplorer's log?",
71+
false,
72+
false);
73+
74+
Hide_On_Startup = new ConfigElement<bool>("Hide On Startup",
75+
"Should UnityExplorer be hidden on startup?",
76+
false,
77+
false);
78+
79+
Last_Window_Anchors = new ConfigElement<string>("Last_Window_Anchors",
80+
"For internal use, the last anchors of the UnityExplorer window.",
81+
DEFAULT_WINDOW_ANCHORS,
82+
true);
83+
84+
Last_Active_Tab = new ConfigElement<int>("Last_Active_Tab",
85+
"For internal use, the last active tab index.",
86+
0,
87+
true);
88+
89+
Last_DebugConsole_State = new ConfigElement<bool>("Last_DebugConsole_State",
90+
"For internal use, the collapsed state of the Debug Console.",
91+
true,
92+
true);
93+
94+
Last_SceneExplorer_State = new ConfigElement<bool>("Last_SceneExplorer_State",
95+
"For internal use, the collapsed state of the Scene Explorer.",
96+
true,
97+
true);
98+
}
99+
100+
// Internal config callback listeners
101+
102+
private static void PanelDragger_OnFinishResize(RectTransform rect)
103+
{
104+
Last_Window_Anchors.Value = RectAnchorsToString(rect);
105+
Handler.SaveConfig();
106+
}
107+
108+
private static void MainMenu_OnActiveTabChanged(int page)
109+
{
110+
Last_Active_Tab.Value = page;
111+
Handler.SaveConfig();
112+
}
113+
114+
private static void DebugConsole_OnToggleShow(bool showing)
115+
{
116+
Last_DebugConsole_State.Value = showing;
117+
Handler.SaveConfig();
118+
}
119+
120+
private static void SceneExplorer_OnToggleShow(bool showing)
121+
{
122+
Last_SceneExplorer_State.Value = showing;
123+
Handler.SaveConfig();
124+
}
125+
126+
// Window Anchors helpers
127+
128+
private const string DEFAULT_WINDOW_ANCHORS = "0.25,0.10,0.78,0.95";
129+
130+
internal static CultureInfo _enCulture = new CultureInfo("en-US");
131+
132+
internal static string RectAnchorsToString(this RectTransform rect)
133+
{
134+
try
135+
{
136+
return string.Format(_enCulture, "{0},{1},{2},{3}", new object[]
137+
{
138+
rect.anchorMin.x,
139+
rect.anchorMin.y,
140+
rect.anchorMax.x,
141+
rect.anchorMax.y
142+
});
143+
}
144+
catch
145+
{
146+
return DEFAULT_WINDOW_ANCHORS;
147+
}
148+
}
149+
150+
internal static void SetAnchorsFromString(this RectTransform panel, string stringAnchors)
151+
{
152+
Vector4 anchors;
153+
try
154+
{
155+
var split = stringAnchors.Split(',');
156+
157+
if (split.Length != 4)
158+
throw new Exception();
159+
160+
anchors.x = float.Parse(split[0], _enCulture);
161+
anchors.y = float.Parse(split[1], _enCulture);
162+
anchors.z = float.Parse(split[2], _enCulture);
163+
anchors.w = float.Parse(split[3], _enCulture);
164+
}
165+
catch
166+
{
167+
anchors = new Vector4(0.25f, 0.1f, 0.78f, 0.95f);
168+
}
169+
170+
panel.anchorMin = new Vector2(anchors.x, anchors.y);
171+
panel.anchorMax = new Vector2(anchors.z, anchors.w);
172+
}
173+
}
174+
}

0 commit comments

Comments
 (0)