Browse Source

Updated TimeScale Edifor

TimeScaleControl
DESKTOP-B4ME9GF\Joshua Reason 6 years ago
parent
commit
f261c57aa5
2 changed files with 47 additions and 28 deletions
  1. +46
    -27
      Assets/Editor/Editor AddOn/TimeScaleEditor/TimeScaleWindow.cs
  2. +1
    -1
      ProjectSettings/TimeManager.asset

+ 46
- 27
Assets/Editor/Editor AddOn/TimeScaleEditor/TimeScaleWindow.cs View File

@ -9,7 +9,8 @@ public class TimeScaleWindow : EditorWindow
// Add menu named "My Window" to the Window menu
private float weightedTimeScale = 0;
private int weightedTimeScale = 1;
private bool isPaused = false;
[MenuItem("AddOn/TimeScale")]
static void Init()
@ -33,62 +34,80 @@ public class TimeScaleWindow : EditorWindow
GUILayout.EndHorizontal();
weightedTimeScale = GUILayout.HorizontalSlider(weightedTimeScale, -100f, 100f);
Time.timeScale = ConvertWeightedToRaw(weightedTimeScale);
weightedTimeScale = (int)GUILayout.HorizontalSlider(weightedTimeScale, -98f, 100f);
weightedTimeScale = Mathf.Clamp(weightedTimeScale,-98,100);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Pause")) weightedTimeScale = -100;
if (GUILayout.Button("Pause")) isPaused = true;
var centeredStyle = GUI.skin.GetStyle("Label");
centeredStyle.alignment = TextAnchor.UpperCenter;
centeredStyle.normal.textColor = Color.black;
if (isPaused)
centeredStyle.normal.textColor = Color.red;
GUILayout.Label(DisplayString(weightedTimeScale), centeredStyle);
GUILayout.Label(DisplayString(Time.timeScale), centeredStyle);
if (GUILayout.Button("Play")) Time.timeScale = 0;
if (GUILayout.Button("Play")) isPaused = false;
GUILayout.EndHorizontal();
Time.timeScale = ConvertWeightedToRaw(weightedTimeScale);
}
private float ConvertWeightedToRaw(float input)
{
if (input > 0)
return Mathf.Lerp(1, 100, input / 100);
if (isPaused)
return 0;
if (input >= 1)
return Mathf.Lerp(0, 100, input / 100);
else
return Mathf.Lerp(1, 0, -input / 100);
return 1 / (-input + 2);
}
private void NextPower(int dir)
{
float sign = Mathf.Sign(weightedTimeScale);
Debug.Log("Sign: " + sign);
float value = Mathf.Abs(weightedTimeScale + dir);
Debug.Log("Value: " + value);
int sign = (int)Mathf.Sign(weightedTimeScale - 1);
int prevValue = (sign >= 0) ? Mathf.Abs(weightedTimeScale) : Mathf.Abs(weightedTimeScale) + 2;
int nextValue = Mathf.NextPowerOfTwo(prevValue);
value = Mathf.NextPowerOfTwo((int)(value));
if (weightedTimeScale == 0)
{
weightedTimeScale = 1;
if (dir < 0)
weightedTimeScale = -2;
return;
}
if (Mathf.Sign(dir) != Mathf.Sign(weightedTimeScale))
value /= 2;
Debug.Log("retVal: " + value + " * " + sign);
weightedTimeScale = value * sign;
}
if (Mathf.Sign(dir) != Mathf.Sign(weightedTimeScale))
nextValue /= 2;
else if (prevValue == nextValue)
nextValue = Mathf.NextPowerOfTwo(prevValue + 1);
if (sign <= 0)
nextValue -= 2;
private void SetSpeed(float newSpeed)
{
Time.timeScale = newSpeed;
weightedTimeScale = nextValue * sign;
}
private string DisplayString(float input)
{
return input.ToString() + " (" + weightedTimeScale + ")";
string retVal = "";
if (input > 1)
return Mathf.Floor(input).ToString();
if (isPaused)
retVal += "(Paused) ";
if (input > 0)
retVal += input.ToString();
else
return ("1/" + Mathf.Floor(-weightedTimeScale));
retVal += "1/" + (-input + 2);
return retVal;
}
}

+ 1
- 1
ProjectSettings/TimeManager.asset View File

@ -5,5 +5,5 @@ TimeManager:
m_ObjectHideFlags: 0
Fixed Timestep: 0.0167
Maximum Allowed Timestep: 0.1
m_TimeScale: 1
m_TimeScale: 8
Maximum Particle Timestep: 0.03

Loading…
Cancel
Save