Last active
August 14, 2026 11:20
-
-
Save nadaked/59f436da0ba49ab7203ede43f8132621 to your computer and use it in GitHub Desktop.
Unity 6000.3 toolbar Time Scale slider with a reset button.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEditor; | |
| using UnityEditor.Toolbars; | |
| using UnityEngine; | |
| namespace Nadaked.Editor.Toolbar | |
| { | |
| public static class ToolbarTimeScale | |
| { | |
| private const string ResetElementId = "Nadaked/TimeScaleReset"; | |
| private const string SliderElementId = "Nadaked/TimeScaleSlider"; | |
| private const float DefaultTimeScale = 1f; | |
| private const float MinTimeScale = 0f; | |
| private const float MaxTimeScale = 5f; | |
| [MainToolbarElement(ResetElementId, defaultDockPosition = MainToolbarDockPosition.Middle)] | |
| public static MainToolbarElement CreateResetButton() | |
| { | |
| var icon = EditorGUIUtility.IconContent("Refresh").image as Texture2D; | |
| var content = new MainToolbarContent(icon, "Reset Time Scale"); | |
| return new MainToolbarButton(content, ResetTimeScale); | |
| } | |
| [MainToolbarElement(SliderElementId, defaultDockPosition = MainToolbarDockPosition.Middle)] | |
| public static MainToolbarElement CreateSlider() | |
| { | |
| var content = new MainToolbarContent( | |
| "Time Scale", | |
| "Change the game time scale"); | |
| return new MainToolbarSlider( | |
| content, | |
| Time.timeScale, | |
| MinTimeScale, | |
| MaxTimeScale, | |
| OnValueChanged) | |
| { | |
| populateContextMenu = menu => | |
| { | |
| menu.AppendAction("Reset", _ => ResetTimeScale()); | |
| } | |
| }; | |
| } | |
| private static void OnValueChanged(float value) | |
| { | |
| Time.timeScale = value; | |
| } | |
| private static void ResetTimeScale() | |
| { | |
| Time.timeScale = DefaultTimeScale; | |
| MainToolbar.Refresh(SliderElementId); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment