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

Commit f280b45

Browse files
committed
3.3.1
* Added a 'Default' button for config values to revert to the default value * Added an internal config entry to save the window position between sessions * Reordered the config settings in the menu so the important ones are at the top * Adjusted the UI for config entries, should be a bit easier to read now. * Adjusted the UI for Dictionaries, the keys and values now alternate background colors. * A few other minor UI fixes and tweaks for 3.3.0
1 parent 456e150 commit f280b45

21 files changed

+141
-68
lines changed

src/Core/Config/ConfigElement.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class ConfigElement<T> : IConfigElement
1616
public Action<T> OnValueChanged;
1717
public Action OnValueChangedNotify { get; set; }
1818

19+
public object DefaultValue { get; }
20+
1921
public T Value
2022
{
2123
get => m_value;
@@ -29,12 +31,13 @@ object IConfigElement.BoxedValue
2931
set => SetValue((T)value);
3032
}
3133

32-
public ConfigElement(string name, string description, T defaultValue, bool isInternal)
34+
public ConfigElement(string name, string description, T defaultValue, bool isInternal = false)
3335
{
3436
Name = name;
3537
Description = description;
3638

3739
m_value = defaultValue;
40+
DefaultValue = defaultValue;
3841

3942
IsInternal = isInternal;
4043

@@ -52,6 +55,8 @@ private void SetValue(T value)
5255

5356
OnValueChanged?.Invoke(value);
5457
OnValueChangedNotify?.Invoke();
58+
59+
ConfigManager.Handler.OnAnyConfigChanged();
5560
}
5661

5762
object IConfigElement.GetLoaderConfigValue() => GetLoaderConfigValue();
@@ -60,5 +65,10 @@ public T GetLoaderConfigValue()
6065
{
6166
return ConfigManager.Handler.GetConfigValue(this);
6267
}
68+
69+
public void RevertToDefaultValue()
70+
{
71+
Value = (T)DefaultValue;
72+
}
6373
}
6474
}

src/Core/Config/ConfigManager.cs

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static class ConfigManager
2424
public static ConfigElement<bool> Hide_On_Startup;
2525

2626
public static ConfigElement<string> Last_Window_Anchors;
27+
public static ConfigElement<string> Last_Window_Position;
2728
public static ConfigElement<int> Last_Active_Tab;
2829
public static ConfigElement<bool> Last_DebugConsole_State;
2930
public static ConfigElement<bool> Last_SceneExplorer_State;
@@ -41,6 +42,7 @@ public static void Init(ConfigHandler configHandler)
4142

4243
SceneExplorer.OnToggleShow += SceneExplorer_OnToggleShow;
4344
PanelDragger.OnFinishResize += PanelDragger_OnFinishResize;
45+
PanelDragger.OnFinishDrag += PanelDragger_OnFinishDrag;
4446
MainMenu.OnActiveTabChanged += MainMenu_OnActiveTabChanged;
4547
DebugConsole.OnToggleShow += DebugConsole_OnToggleShow;
4648
}
@@ -55,39 +57,40 @@ private static void CreateConfigElements()
5557
{
5658
Main_Menu_Toggle = new ConfigElement<KeyCode>("Main Menu Toggle",
5759
"The UnityEngine.KeyCode to toggle the UnityExplorer Menu.",
58-
KeyCode.F7,
60+
KeyCode.F7);
61+
62+
Hide_On_Startup = new ConfigElement<bool>("Hide On Startup",
63+
"Should UnityExplorer be hidden on startup?",
64+
false);
65+
66+
Log_Unity_Debug = new ConfigElement<bool>("Log Unity Debug",
67+
"Should UnityEngine.Debug.Log messages be printed to UnityExplorer's log?",
5968
false);
6069

6170
Force_Unlock_Mouse = new ConfigElement<bool>("Force Unlock Mouse",
6271
"Force the Cursor to be unlocked (visible) when the UnityExplorer menu is open.",
63-
true,
64-
false);
72+
true);
6573

6674
Default_Page_Limit = new ConfigElement<int>("Default Page Limit",
6775
"The default maximum number of elements per 'page' in UnityExplorer.",
68-
25,
69-
false);
76+
25);
7077

7178
Default_Output_Path = new ConfigElement<string>("Default Output Path",
7279
"The default output path when exporting things from UnityExplorer.",
73-
Path.Combine(ExplorerCore.Loader.ExplorerFolder, "Output"),
74-
false);
75-
76-
Log_Unity_Debug = new ConfigElement<bool>("Log Unity Debug",
77-
"Should UnityEngine.Debug.Log messages be printed to UnityExplorer's log?",
78-
false,
79-
false);
80+
Path.Combine(ExplorerCore.Loader.ExplorerFolder, "Output"));
8081

81-
Hide_On_Startup = new ConfigElement<bool>("Hide On Startup",
82-
"Should UnityExplorer be hidden on startup?",
83-
false,
84-
false);
82+
// Internal configs
8583

8684
Last_Window_Anchors = new ConfigElement<string>("Last_Window_Anchors",
8785
"For internal use, the last anchors of the UnityExplorer window.",
8886
DEFAULT_WINDOW_ANCHORS,
8987
true);
9088

89+
Last_Window_Position = new ConfigElement<string>("Last_Window_Position",
90+
"For internal use, the last position of the UnityExplorer window.",
91+
DEFAULT_WINDOW_POSITION,
92+
true);
93+
9194
Last_Active_Tab = new ConfigElement<int>("Last_Active_Tab",
9295
"For internal use, the last active tab index.",
9396
0,
@@ -108,31 +111,33 @@ private static void CreateConfigElements()
108111

109112
private static void PanelDragger_OnFinishResize(RectTransform rect)
110113
{
111-
Last_Window_Anchors.Value = RectAnchorsToString(rect);
112-
Handler.OnAnyConfigChanged();
114+
Last_Window_Anchors.Value = rect.RectAnchorsToString();
115+
}
116+
117+
private static void PanelDragger_OnFinishDrag(RectTransform rect)
118+
{
119+
Last_Window_Position.Value = rect.RectPositionToString();
113120
}
114121

115122
private static void MainMenu_OnActiveTabChanged(int page)
116123
{
117124
Last_Active_Tab.Value = page;
118-
Handler.OnAnyConfigChanged();
119125
}
120126

121127
private static void DebugConsole_OnToggleShow(bool showing)
122128
{
123129
Last_DebugConsole_State.Value = showing;
124-
Handler.OnAnyConfigChanged();
125130
}
126131

127132
private static void SceneExplorer_OnToggleShow(bool showing)
128133
{
129134
Last_SceneExplorer_State.Value = showing;
130-
Handler.OnAnyConfigChanged();
131135
}
132136

133137
// Window Anchors helpers
134138

135139
private const string DEFAULT_WINDOW_ANCHORS = "0.25,0.10,0.78,0.95";
140+
private const string DEFAULT_WINDOW_POSITION = "0,0";
136141

137142
internal static CultureInfo _enCulture = new CultureInfo("en-US");
138143

@@ -177,5 +182,33 @@ internal static void SetAnchorsFromString(this RectTransform panel, string strin
177182
panel.anchorMin = new Vector2(anchors.x, anchors.y);
178183
panel.anchorMax = new Vector2(anchors.z, anchors.w);
179184
}
185+
186+
internal static string RectPositionToString(this RectTransform rect)
187+
{
188+
return string.Format(_enCulture, "{0},{1}", new object[]
189+
{
190+
rect.localPosition.x, rect.localPosition.y
191+
});
192+
}
193+
194+
internal static void SetPositionFromString(this RectTransform rect, string stringPosition)
195+
{
196+
try
197+
{
198+
var split = stringPosition.Split(',');
199+
200+
if (split.Length != 2)
201+
throw new Exception();
202+
203+
Vector3 vector = rect.localPosition;
204+
vector.x = float.Parse(split[0], _enCulture);
205+
vector.y = float.Parse(split[1], _enCulture);
206+
rect.localPosition = vector;
207+
}
208+
catch //(Exception ex)
209+
{
210+
//ExplorerCore.LogWarning("Exception setting window position: " + ex);
211+
}
212+
}
180213
}
181214
}

src/Core/Config/IConfigElement.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ public interface IConfigElement
1111
Type ElementType { get; }
1212

1313
object BoxedValue { get; set; }
14+
object DefaultValue { get; }
1415

1516
object GetLoaderConfigValue();
1617

18+
void RevertToDefaultValue();
19+
1720
Action OnValueChangedNotify { get; set; }
1821
}
1922
}

src/ExplorerCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace UnityExplorer
1212
public class ExplorerCore
1313
{
1414
public const string NAME = "UnityExplorer";
15-
public const string VERSION = "3.3.0";
15+
public const string VERSION = "3.3.1";
1616
public const string AUTHOR = "Sinai";
1717
public const string GUID = "com.sinai.unityexplorer";
1818

src/UI/CacheObject/CacheConfigEntry.cs

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override void CreateIValue(object value, Type fallbackType)
3535
{
3636
IValue = InteractiveValue.Create(value, fallbackType);
3737
IValue.Owner = this;
38-
IValue.m_mainContentParent = m_rightGroup;
38+
IValue.m_mainContentParent = m_mainGroup;
3939
IValue.m_subContentParent = this.m_subContent;
4040
}
4141

@@ -52,26 +52,28 @@ public override void SetValue()
5252
ConfigManager.Handler.OnAnyConfigChanged();
5353
}
5454

55-
internal GameObject m_leftGroup;
56-
internal GameObject m_rightGroup;
55+
internal GameObject m_mainGroup;
56+
//internal GameObject m_leftGroup;
57+
//internal GameObject m_rightGroup;
58+
//internal GameObject m_secondRow;
5759

5860
internal override void ConstructUI()
5961
{
6062
base.ConstructUI();
6163

62-
var vertGroup = UIFactory.CreateVerticalGroup(m_mainContent, "ConfigHolder", true, false, true, true, 5, new Vector4(2, 2, 2, 2));
64+
m_mainGroup = UIFactory.CreateVerticalGroup(m_mainContent, "ConfigHolder", true, false, true, true, 5, new Vector4(2, 2, 2, 2));
6365

64-
var horiGroup = UIFactory.CreateHorizontalGroup(vertGroup, "ConfigEntryHolder", true, false, true, true);
66+
var horiGroup = UIFactory.CreateHorizontalGroup(m_mainGroup, "ConfigEntryHolder", false, false, true, true, childAlignment: TextAnchor.MiddleLeft);
6567
UIFactory.SetLayoutElement(horiGroup, minHeight: 30, flexibleHeight: 0);
6668

67-
// left group
69+
//// left group
6870

69-
m_leftGroup = UIFactory.CreateHorizontalGroup(horiGroup, "ConfigTitleGroup", false, false, true, true, 4, default, new Color(1, 1, 1, 0));
70-
UIFactory.SetLayoutElement(m_leftGroup, minHeight: 25, flexibleHeight: 0, minWidth: 125, flexibleWidth: 200);
71+
//m_leftGroup = UIFactory.CreateHorizontalGroup(horiGroup, "ConfigTitleGroup", false, false, true, true, 4, default, new Color(1, 1, 1, 0));
72+
//UIFactory.SetLayoutElement(m_leftGroup, minHeight: 25, flexibleHeight: 0, minWidth: 200, flexibleWidth: 0);
7173

7274
// config entry label
7375

74-
var configLabel = UIFactory.CreateLabel(m_leftGroup, "ConfigLabel", this.RefConfig.Name, TextAnchor.MiddleLeft);
76+
var configLabel = UIFactory.CreateLabel(horiGroup, "ConfigLabel", this.RefConfig.Name, TextAnchor.MiddleLeft);
7577
var leftRect = configLabel.GetComponent<RectTransform>();
7678
leftRect.anchorMin = Vector2.zero;
7779
leftRect.anchorMax = Vector2.one;
@@ -80,23 +82,39 @@ internal override void ConstructUI()
8082
leftRect.sizeDelta = Vector2.zero;
8183
UIFactory.SetLayoutElement(configLabel.gameObject, minWidth: 250, minHeight: 25, flexibleWidth: 0, flexibleHeight: 0);
8284

83-
// right group
85+
// Default button
8486

85-
m_rightGroup = UIFactory.CreateVerticalGroup(horiGroup, "ConfigValueGroup", false, false, true, true, 2, new Vector4(4,2,0,0),
86-
new Color(1, 1, 1, 0));
87-
UIFactory.SetLayoutElement(m_rightGroup, minHeight: 25, minWidth: 150, flexibleHeight: 0, flexibleWidth: 5000);
87+
var defaultButton = UIFactory.CreateButton(horiGroup,
88+
"RevertDefaultButton",
89+
"Default",
90+
() => { RefConfig.RevertToDefaultValue(); },
91+
new Color(0.3f, 0.3f, 0.3f));
92+
UIFactory.SetLayoutElement(defaultButton.gameObject, minWidth: 80, minHeight: 22, flexibleWidth: 0);
93+
94+
//// right group
95+
96+
//m_rightGroup = UIFactory.CreateVerticalGroup(horiGroup, "ConfigValueGroup", false, false, true, true, 4, default, new Color(1, 1, 1, 0));
97+
//UIFactory.SetLayoutElement(m_rightGroup, minHeight: 25, minWidth: 150, flexibleHeight: 0, flexibleWidth: 5000);
98+
99+
// Description label
100+
101+
var desc = UIFactory.CreateLabel(m_mainGroup, "Description", $"<i>{RefConfig.Description}</i>", TextAnchor.MiddleLeft, Color.grey);
102+
UIFactory.SetLayoutElement(desc.gameObject, minWidth: 250, minHeight: 20, flexibleWidth: 9999, flexibleHeight: 0);
103+
104+
//// Second row (IValue)
105+
106+
//m_secondRow = UIFactory.CreateHorizontalGroup(m_mainGroup, "DescriptionRow", false, false, true, true, 4, new Color(0.08f, 0.08f, 0.08f));
107+
108+
// IValue
88109

89110
if (IValue != null)
90111
{
91-
IValue.m_mainContentParent = m_rightGroup;
112+
IValue.m_mainContentParent = m_mainGroup;
92113
IValue.m_subContentParent = this.m_subContent;
93114
}
94115

95-
// Config description label
96-
97-
UIFactory.CreateLabel(vertGroup, "Description", $"<i>{RefConfig.Description}</i>", TextAnchor.MiddleLeft, Color.grey);
98-
99-
m_subContent.transform.SetAsLastSibling();
116+
// makes the subcontent look nicer
117+
m_subContent.transform.SetParent(m_mainGroup.transform, false);
100118
}
101119
}
102120
}

src/UI/CacheObject/CachePaired.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ internal override void ConstructUI()
5050
{
5151
base.ConstructUI();
5252

53+
Color bgColor = this.PairType == PairTypes.Key
54+
? new Color(0.07f, 0.07f, 0.07f)
55+
: new Color(0.1f, 0.1f, 0.1f);
56+
5357
var rowObj = UIFactory.CreateHorizontalGroup(m_mainContent, "PairedGroup", false, false, true, true, 0, new Vector4(0,0,5,2),
54-
new Color(1, 1, 1, 0));
58+
bgColor);
5559

5660
var indexLabel = UIFactory.CreateLabel(rowObj, "IndexLabel", $"{this.PairType} {this.Index}:", TextAnchor.MiddleLeft);
5761
UIFactory.SetLayoutElement(indexLabel.gameObject, minWidth: 80, flexibleWidth: 30, minHeight: 25);

src/UI/InteractiveValues/InteractiveEnum.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public override void ConstructSubcontent()
146146

147147
// dropdown
148148

149-
var dropdownObj = UIFactory.CreateDropdown(groupObj, out m_dropdown, "<notset>", 14, null);
149+
var dropdownObj = UIFactory.CreateDropdown(groupObj, out m_dropdown, "", 14, null);
150150
UIFactory.SetLayoutElement(dropdownObj, minWidth: 150, minHeight: 25, flexibleWidth: 120);
151151

152152
foreach (var kvp in m_values)

src/UI/InteractiveValues/InteractiveString.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public override void ConstructUI(GameObject parent, GameObject subGroup)
115115

116116
m_labelLayout = m_baseLabel.gameObject.GetComponent<LayoutElement>();
117117

118-
m_readonlyInput = UIFactory.CreateLabel(m_valueContent, "ReadonlyLabel", "<notset>", TextAnchor.MiddleLeft);
118+
m_readonlyInput = UIFactory.CreateLabel(m_valueContent, "ReadonlyLabel", "", TextAnchor.MiddleLeft);
119119
m_readonlyInput.horizontalOverflow = HorizontalWrapMode.Overflow;
120120

121121
var testFitter = m_readonlyInput.gameObject.AddComponent<ContentSizeFitter>();
@@ -128,7 +128,7 @@ public override void ConstructSubcontent()
128128
{
129129
base.ConstructSubcontent();
130130

131-
var groupObj = UIFactory.CreateVerticalGroup(m_subContentParent, "SubContent", true, false, true, true, 4, new Vector4(3,3,3,3),
131+
var groupObj = UIFactory.CreateVerticalGroup(m_subContentParent, "SubContent", false, false, true, true, 4, new Vector4(3,3,3,3),
132132
new Color(1, 1, 1, 0));
133133

134134
m_hiddenObj = UIFactory.CreateLabel(groupObj, "HiddenLabel", "", TextAnchor.MiddleLeft).gameObject;

src/UI/InteractiveValues/InteractiveValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public virtual void ConstructUI(GameObject parent, GameObject subGroup)
338338

339339
// value label
340340

341-
m_baseLabel = UIFactory.CreateLabel(m_valueContent, "ValueLabel", "<not set>", TextAnchor.MiddleLeft);
341+
m_baseLabel = UIFactory.CreateLabel(m_valueContent, "ValueLabel", "", TextAnchor.MiddleLeft);
342342
UIFactory.SetLayoutElement(m_baseLabel.gameObject, flexibleWidth: 9000, minHeight: 25);
343343

344344
m_subContentParent = subGroup;

src/UI/Main/Home/InspectorManager.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,21 @@ private static void ConstructToolbar(GameObject topRowObj)
200200
UIFactory.CreateHorizontalGroup(topRowObj, "Toolbar", false, false, true, true, 10, new Vector4(2, 2, 2, 2), new Color(1,1,1,0));
201201

202202
// inspect under mouse button
203-
AddMouseInspectButton(topRowObj, InspectUnderMouse.MouseInspectMode.UI);
204-
AddMouseInspectButton(topRowObj, InspectUnderMouse.MouseInspectMode.World);
203+
AddMouseInspectButton(topRowObj, "UI", InspectUnderMouse.MouseInspectMode.UI);
204+
AddMouseInspectButton(topRowObj, "3D", InspectUnderMouse.MouseInspectMode.World);
205205
}
206206

207-
private static void AddMouseInspectButton(GameObject topRowObj, InspectUnderMouse.MouseInspectMode mode)
207+
private static void AddMouseInspectButton(GameObject topRowObj, string suffix, InspectUnderMouse.MouseInspectMode mode)
208208
{
209-
string lbl = "Mouse Inspect";
210-
if (mode == InspectUnderMouse.MouseInspectMode.UI)
211-
lbl += " (UI)";
209+
string lbl = $"Mouse Inspect ({suffix})";
212210

213211
var inspectObj = UIFactory.CreateButton(topRowObj,
214212
lbl,
215213
lbl,
216214
() => { InspectUnderMouse.StartInspect(mode); },
217215
new Color(0.2f, 0.2f, 0.2f));
218216

219-
UIFactory.SetLayoutElement(inspectObj.gameObject, minWidth: 120, flexibleWidth: 0);
217+
UIFactory.SetLayoutElement(inspectObj.gameObject, minWidth: 150, flexibleWidth: 0);
220218
}
221219
}
222220
}

0 commit comments

Comments
 (0)