From 8e744bce683ec5a4d68fee51d545bb2e5ccbb073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alper=20=C3=9Cnl=C3=BC?= <52657487+alperunlu07@users.noreply.github.com> Date: Wed, 29 Apr 2026 10:47:32 +0300 Subject: [PATCH] Persist FPS slider and Enter Play Mode dropdown across editor restarts ToolbarFPSSlider: - Mark selectedFramerate [SerializeField] (default 60) so the chosen value survives domain reload / editor restart. - Replace global GUI.changed with EditorGUI.BeginChangeCheck/EndChangeCheck to avoid reacting to unrelated GUI events. - Save() the toolbar setting on change so toolbar-side edits are persisted even when the Project Settings panel is not open. ToolbarEnterPlayMode: - Mark selectedEnterPlayMode [SerializeField] as a defensive cache. - Lazy-init enterPlayModeOption labels in OnDrawInToolbar in case the initializer hasn't run yet. - Apply selection to EditorSettings via a dedicated helper, called both on Init() and on user change, so the saved value is enforced on editor open. - Switch to BeginChangeCheck/EndChangeCheck instead of GUI.changed. - Save() the toolbar setting on change. --- .../ToolbarElements/ToolbarEnterPlayMode.cs | 33 +++++++++++++------ .../ToolbarElements/ToolbarFPSSlider.cs | 17 +++++++--- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Editor/CustomToolbar/Scripts/ToolbarElements/ToolbarEnterPlayMode.cs b/Editor/CustomToolbar/Scripts/ToolbarElements/ToolbarEnterPlayMode.cs index eeef8c1..d6cee1d 100644 --- a/Editor/CustomToolbar/Scripts/ToolbarElements/ToolbarEnterPlayMode.cs +++ b/Editor/CustomToolbar/Scripts/ToolbarElements/ToolbarEnterPlayMode.cs @@ -2,12 +2,13 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityToolbarExtender; using UnityEditor; [Serializable] internal class ToolbarEnterPlayMode : BaseToolbarElement { #if UNITY_2019_3_OR_NEWER - int selectedEnterPlayMode; + [SerializeField] int selectedEnterPlayMode; string[] enterPlayModeOption; #endif @@ -22,6 +23,9 @@ public override void Init() { "Reload Domain", "FastMode", }; +#if UNITY_2019_3_OR_NEWER + ApplyToEditorSettings(); +#endif } protected override void OnDrawInList(Rect position) { @@ -30,17 +34,26 @@ protected override void OnDrawInList(Rect position) { protected override void OnDrawInToolbar() { #if UNITY_2019_3_OR_NEWER - if (EditorSettings.enterPlayModeOptionsEnabled) { - EnterPlayModeOptions option = EditorSettings.enterPlayModeOptions; - selectedEnterPlayMode = (int)option + 1; + if (enterPlayModeOption == null) + Init(); + + EditorGUI.BeginChangeCheck(); + int newSelection = EditorGUILayout.Popup(selectedEnterPlayMode, enterPlayModeOption, GUILayout.Width(WidthInToolbar)); + if (EditorGUI.EndChangeCheck() && 0 <= newSelection && newSelection < enterPlayModeOption.Length) { + selectedEnterPlayMode = newSelection; + ApplyToEditorSettings(); +#if UNITY_2020_3_OR_NEWER + CustomToolbarSetting.instance.Save(); +#endif } +#endif + } - selectedEnterPlayMode = EditorGUILayout.Popup(selectedEnterPlayMode, enterPlayModeOption, GUILayout.Width(WidthInToolbar)); - - if (GUI.changed && 0 <= selectedEnterPlayMode && selectedEnterPlayMode < enterPlayModeOption.Length) { - EditorSettings.enterPlayModeOptionsEnabled = selectedEnterPlayMode != 0; +#if UNITY_2019_3_OR_NEWER + void ApplyToEditorSettings() { + EditorSettings.enterPlayModeOptionsEnabled = selectedEnterPlayMode != 0; + if (selectedEnterPlayMode > 0) EditorSettings.enterPlayModeOptions = (EnterPlayModeOptions)(selectedEnterPlayMode - 1); - } -#endif } +#endif } diff --git a/Editor/CustomToolbar/Scripts/ToolbarElements/ToolbarFPSSlider.cs b/Editor/CustomToolbar/Scripts/ToolbarElements/ToolbarFPSSlider.cs index 6baff26..b2fe207 100644 --- a/Editor/CustomToolbar/Scripts/ToolbarElements/ToolbarFPSSlider.cs +++ b/Editor/CustomToolbar/Scripts/ToolbarElements/ToolbarFPSSlider.cs @@ -2,20 +2,20 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityToolbarExtender; using UnityEditor; [Serializable] internal class ToolbarFPSSlider : BaseToolbarElement { [SerializeField] int minFPS = 1; [SerializeField] int maxFPS = 120; - - int selectedFramerate; + [SerializeField] int selectedFramerate = 60; public override string NameInList => "[Slider] FPS"; public override int SortingGroup => 1; public override void Init() { - if (selectedFramerate == 0) + if (selectedFramerate <= 0) selectedFramerate = 60; } @@ -43,7 +43,16 @@ protected override void OnDrawInList(Rect position) { protected override void OnDrawInToolbar() { EditorGUILayout.LabelField("FPS", GUILayout.Width(30)); - selectedFramerate = EditorGUILayout.IntSlider("", selectedFramerate, minFPS, maxFPS, GUILayout.Width(WidthInToolbar - 30.0f)); + + EditorGUI.BeginChangeCheck(); + int newFramerate = EditorGUILayout.IntSlider("", selectedFramerate, minFPS, maxFPS, GUILayout.Width(WidthInToolbar - 30.0f)); + if (EditorGUI.EndChangeCheck()) { + selectedFramerate = newFramerate; +#if UNITY_2020_3_OR_NEWER + CustomToolbarSetting.instance.Save(); +#endif + } + if (EditorApplication.isPlaying && selectedFramerate != Application.targetFrameRate) Application.targetFrameRate = selectedFramerate; }