Just pulled out the time scale as a separate window(Tools > Time Scale Editor) from time manager window(Edit > Project Settings > Time). It also recovers the value if has any changes in PlayMode.
Last active
April 24, 2017 10:39
-
-
Save gemfile0/2796d8ee30a669202b59af660b958ea2 to your computer and use it in GitHub Desktop.
Time Scale Window in Unity
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 UnityEngine; | |
using UnityEditor; | |
public class TimeScaleWindow: EditorWindow | |
{ | |
float timeScale = 1.0f; | |
float timeScaleBefore = 0f; | |
[MenuItem("Tools/Time Scale Window")] | |
public static void OpenWindow() | |
{ | |
var window = EditorWindow.GetWindow(typeof(TimeScaleWindow)); | |
window.titleContent = new GUIContent("Time Scale Window"); | |
} | |
void OnEnable() | |
{ | |
EditorApplication.playmodeStateChanged += OnPlaymodeStateChange; | |
} | |
void OnDiable() | |
{ | |
EditorApplication.playmodeStateChanged -= OnPlaymodeStateChange; | |
} | |
void OnGUI() | |
{ | |
timeScale = EditorGUILayout.Slider("Time Scale", timeScale, 0.0f, 1.0f); | |
ChangeTimeScale(timeScale); | |
} | |
void OnPlaymodeStateChange() | |
{ | |
if (EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying) | |
{ | |
timeScaleBefore = timeScale; | |
} | |
else if (!EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying) | |
{ | |
timeScale = timeScaleBefore; | |
ChangeTimeScale(timeScale); | |
Repaint(); | |
} | |
} | |
void ChangeTimeScale(float value) | |
{ | |
if (timeScale != Time.timeScale) { Time.timeScale = timeScale; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment