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; }