Skip to content

Commit 6c7c9af

Browse files
authored
feat: add reset config button to inspector (#7)
1 parent b2aefad commit 6c7c9af

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

Editor/CustomInspectors/ThemeConfigManagerInspector.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class ThemeConfigManagerInspector : UnityEditor.Editor
2424

2525
private readonly string RefreshButtonName = "RefreshButton";
2626

27+
private readonly string ResetConfigButtonName = "ResetConfigButton";
28+
2729
private void ExportThemeConfigToJson()
2830
{
2931
ThemeConfigManager themeConfigManager = (ThemeConfigManager)target;
@@ -42,6 +44,18 @@ private void ImportThemeConfigFromJson()
4244

4345
}
4446

47+
private void ResetConfig()
48+
{
49+
ThemeConfigManager themeConfigManager = (ThemeConfigManager)target;
50+
51+
themeConfigManager.ResetThemeConfig();
52+
53+
EditorUtility.SetDirty(themeConfigManager);
54+
55+
themeConfigManager.Logger.LogProgress("Reset Theme Config");
56+
57+
}
58+
4559
private void GenerateUSS()
4660
{
4761
ThemeConfigManager themeConfigManager = (ThemeConfigManager)target;
@@ -152,6 +166,10 @@ public override VisualElement CreateInspectorGUI()
152166
Button refreshButton = myInspector.Q<Button>(RefreshButtonName);
153167
refreshButton.clickable.clicked += Refresh;
154168

169+
// Get the reset button from the UXML and assign it its click event
170+
Button resetConfigButton = myInspector.Q<Button>(ResetConfigButtonName);
171+
resetConfigButton.clickable.clicked += ResetConfig;
172+
155173

156174

157175
// Get the log level enum dropdown from the UXML

Editor/CustomInspectors/Theme_Config_Inspector_UXML.uxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<ui:VisualElement style="flex-grow: 1;">
1818
<uie:ObjectField label="JSON File" binding-path="m_importThemeConfigJsonFile" allow-scene-objects="false" type="UnityEngine.TextAsset, UnityEngine.CoreModule" name="ImportJsonFileField" />
1919
<ui:Button text="Import Config" parse-escape-sequences="true" display-tooltip-when-elided="true" name="ImportConfigButton" style="margin-top: 8px;" />
20+
<ui:Button text="Reset" parse-escape-sequences="true" display-tooltip-when-elided="true" name="ResetConfigButton" tooltip="Resets the theme config to the default one." class="themeconfig__button__secondary" style="margin-top: 8px;" />
2021
<ui:Label tabindex="-1" text="&lt;b&gt;WARNING&lt;/b&gt;: this will overwrite your current config!" parse-escape-sequences="true" display-tooltip-when-elided="true" style="color: rgb(255, 146, 146); -unity-text-align: upper-center; margin-top: 8px;" />
2122
</ui:VisualElement>
2223
</ui:Foldout>

Editor/Lib/ConfigDisplay/ThemeConfigManager.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,22 @@ public void ImportThemeConfigFromJson()
290290
{
291291
if (m_importThemeConfigJsonFile == null)
292292
{
293-
Logger.LogWarning("No import file provided, using the default theme config instead");
294-
LoadDefaultThemeConfig();
293+
Logger.LogError("No import file provided.");
295294
return;
296295
}
297296

298297
var json = m_importThemeConfigJsonFile.text;
299298
LoadThemeConfigDisplayFromJsonString(json);
300299
}
301300

301+
/// <summary>
302+
/// Resets the theme config to the default theme config.
303+
/// </summary>
304+
public void ResetThemeConfig()
305+
{
306+
LoadDefaultThemeConfig();
307+
}
308+
302309
/// <summary>
303310
/// Exports the theme config to json using the provided export path.
304311
/// </summary>

0 commit comments

Comments
 (0)