|
@ -0,0 +1,94 @@ |
|
|
|
|
|
using System.Collections; |
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
using UnityEngine; |
|
|
|
|
|
using UnityEditor; |
|
|
|
|
|
using UnityEngine.UI; |
|
|
|
|
|
|
|
|
|
|
|
public class TimeScaleWindow : EditorWindow |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
// Add menu named "My Window" to the Window menu
|
|
|
|
|
|
|
|
|
|
|
|
private float weightedTimeScale = 0; |
|
|
|
|
|
|
|
|
|
|
|
[MenuItem("AddOn/TimeScale")] |
|
|
|
|
|
static void Init() |
|
|
|
|
|
{ |
|
|
|
|
|
// Get existing open window or if none, make a new one:
|
|
|
|
|
|
TimeScaleWindow window = (TimeScaleWindow)EditorWindow.GetWindow(typeof(TimeScaleWindow)); |
|
|
|
|
|
window.Show(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void OnGUI() |
|
|
|
|
|
{ |
|
|
|
|
|
GUILayout.Label("Base Settings", EditorStyles.boldLabel); |
|
|
|
|
|
|
|
|
|
|
|
GUILayout.BeginHorizontal(); |
|
|
|
|
|
|
|
|
|
|
|
if (GUILayout.Button("<<")) NextPower(-1); |
|
|
|
|
|
if (GUILayout.Button("<")) weightedTimeScale--; |
|
|
|
|
|
|
|
|
|
|
|
if (GUILayout.Button(">")) weightedTimeScale++; |
|
|
|
|
|
if (GUILayout.Button(">>")) NextPower(1); |
|
|
|
|
|
|
|
|
|
|
|
GUILayout.EndHorizontal(); |
|
|
|
|
|
|
|
|
|
|
|
weightedTimeScale = GUILayout.HorizontalSlider(weightedTimeScale, -100f, 100f); |
|
|
|
|
|
|
|
|
|
|
|
Time.timeScale = ConvertWeightedToRaw(weightedTimeScale); |
|
|
|
|
|
|
|
|
|
|
|
GUILayout.BeginHorizontal(); |
|
|
|
|
|
|
|
|
|
|
|
if (GUILayout.Button("Pause")) weightedTimeScale = -100; |
|
|
|
|
|
var centeredStyle = GUI.skin.GetStyle("Label"); |
|
|
|
|
|
centeredStyle.alignment = TextAnchor.UpperCenter; |
|
|
|
|
|
|
|
|
|
|
|
GUILayout.Label(DisplayString(Time.timeScale), centeredStyle); |
|
|
|
|
|
if (GUILayout.Button("Play")) Time.timeScale = 0; |
|
|
|
|
|
GUILayout.EndHorizontal(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private float ConvertWeightedToRaw(float input) |
|
|
|
|
|
{ |
|
|
|
|
|
if (input > 0) |
|
|
|
|
|
return Mathf.Lerp(1, 100, input / 100); |
|
|
|
|
|
else |
|
|
|
|
|
return Mathf.Lerp(1, 0, -input / 100); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void NextPower(int dir) |
|
|
|
|
|
{ |
|
|
|
|
|
float sign = Mathf.Sign(weightedTimeScale); |
|
|
|
|
|
Debug.Log("Sign: " + sign); |
|
|
|
|
|
float value = Mathf.Abs(weightedTimeScale + dir); |
|
|
|
|
|
Debug.Log("Value: " + value); |
|
|
|
|
|
|
|
|
|
|
|
value = Mathf.NextPowerOfTwo((int)(value)); |
|
|
|
|
|
|
|
|
|
|
|
if (Mathf.Sign(dir) != Mathf.Sign(weightedTimeScale)) |
|
|
|
|
|
value /= 2; |
|
|
|
|
|
|
|
|
|
|
|
Debug.Log("retVal: " + value + " * " + sign); |
|
|
|
|
|
weightedTimeScale = value * sign; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void SetSpeed(float newSpeed) |
|
|
|
|
|
{ |
|
|
|
|
|
Time.timeScale = newSpeed; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private string DisplayString(float input) |
|
|
|
|
|
{ |
|
|
|
|
|
return input.ToString() + " (" + weightedTimeScale + ")"; |
|
|
|
|
|
|
|
|
|
|
|
if (input > 1) |
|
|
|
|
|
return Mathf.Floor(input).ToString(); |
|
|
|
|
|
else |
|
|
|
|
|
return ("1/" + Mathf.Floor(-weightedTimeScale)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |