Browse Source

Started work on Time Scale Editor

TimeScaleControl
DESKTOP-B4ME9GF\Joshua Reason 6 years ago
parent
commit
8180868a6a
3 changed files with 113 additions and 0 deletions
  1. +8
    -0
      Assets/Editor/Editor AddOn/TimeScaleEditor.meta
  2. +94
    -0
      Assets/Editor/Editor AddOn/TimeScaleEditor/TimeScaleWindow.cs
  3. +11
    -0
      Assets/Editor/Editor AddOn/TimeScaleEditor/TimeScaleWindow.cs.meta

+ 8
- 0
Assets/Editor/Editor AddOn/TimeScaleEditor.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d4a830bb77ae79d4883e970695e3ac1f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 94
- 0
Assets/Editor/Editor AddOn/TimeScaleEditor/TimeScaleWindow.cs View File

@ -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));
}
}

+ 11
- 0
Assets/Editor/Editor AddOn/TimeScaleEditor/TimeScaleWindow.cs.meta View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9eb2610747faaf14689b38a264c25baa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Loading…
Cancel
Save