Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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) {
Expand All @@ -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
}
17 changes: 13 additions & 4 deletions Editor/CustomToolbar/Scripts/ToolbarElements/ToolbarFPSSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down