private static void LoadAllPreferenceValues() { if (!s_prefsLoaded) { s_isEnabled = EditorPrefs.GetBool(KEY_EDITORPREF_IS_ENABLED, DEFAULT_IS_ENABLED); s_mode = (AutoThemeMode)EditorPrefs.GetInt(KEY_EDITORPREF_MODE, (int)DEFAULT_MODE); s_lightThemeTime = TimeSpan.Parse(EditorPrefs.GetString(KEY_EDITORPREF_LIGHT_THEME_TIME, DEFAULT_LIGHT_THEME_TIME.ToString())); s_darkThemeTime = TimeSpan.Parse(EditorPrefs.GetString(KEY_EDITORPREF_DARK_THEME_TIME, DEFAULT_DARK_THEME_TIME.ToString())); gui_lightThemeTime = s_lightThemeTime.ToString(); gui_darkThemeTime = s_darkThemeTime.ToString(); s_prefsLoaded = true; } }
public override void OnGUI(string searchContext) { bool areValuesValid = true; s_isEnabled = EditorGUILayout.Toggle("Enabled", s_isEnabled); if (s_isEnabled) { s_mode = (AutoThemeMode)EditorGUILayout.EnumPopup("Change theme based on", s_mode); if (s_mode == AutoThemeMode.Time) { gui_lightThemeTime = EditorGUILayout.DelayedTextField("Enable light theme at", gui_lightThemeTime); gui_darkThemeTime = EditorGUILayout.DelayedTextField("Enable dark theme at", gui_darkThemeTime); EditorGUILayout.Space(); try { s_lightThemeTime = TimeSpan.Parse(gui_lightThemeTime); } catch (Exception e) when(e is FormatException || e is OverflowException) { areValuesValid = false; EditorGUILayout.HelpBox($"Invalid light theme time! Must be hh:mm:ss (24-hour format).", MessageType.Error); } try { s_darkThemeTime = TimeSpan.Parse(gui_darkThemeTime); } catch (Exception e) when(e is FormatException || e is OverflowException) { areValuesValid = false; EditorGUILayout.HelpBox($"Invalid dark theme time! Must be hh:mm:ss (24-hour format).", MessageType.Error); } } } if (GUI.changed && areValuesValid) { SaveAllPreferenceValues(); } }