Modified the TimeScaleController to work in tandem with UnityExplorer's native time scale control.

This commit is contained in:
originalnicodr committed 2023-02-16 19:21:44 -03:00
1 parent f0b594fd30
commit ef4401fac0
3 files changed
+17 -12

No files matched your search

+7 -6
View File
@@ -78,7 +78,7 @@ namespace UnityExplorer
public TimeScaleController(System.IntPtr ptr) : base(ptr) { }
#endif
bool pause;
public bool pause;
bool settingTimeScale;
internal static void Setup()
@@ -96,12 +96,13 @@ namespace UnityExplorer
public void Update()
{
if (InputManager.GetKeyDown(KeyCode.Pause))
{
pause = !pause;
if (pause)
SetTimeScale(0f);
else
SetTimeScale(1f);
if (pause)
SetTimeScale(0f);
else
SetTimeScale(1f);
}
}
void SetTimeScale(float time)
+10 -6
View File
@@ -28,15 +28,19 @@ namespace UnityExplorer.UI.Widgets
InputFieldRef timeInput;
float desiredTime;
bool settingTimeScale;
TimeScaleController timeScaleController = GameObject.Find("TimeScaleController").GetComponent<TimeScaleController>();
public void Update()
{
// Fallback in case Time.timeScale patch failed for whatever reason
if (locked)
SetTimeScale(desiredTime);
//We don't want Unity Explorer's native time scale control to interfere with ours.
if (!timeScaleController.pause){
// Fallback in case Time.timeScale patch failed for whatever reason
if (locked)
SetTimeScale(desiredTime);
if (!timeInput.Component.isFocused)
timeInput.Text = Time.timeScale.ToString("F2");
if (!timeInput.Component.isFocused)
timeInput.Text = Time.timeScale.ToString("F2");
}
}
void SetTimeScale(float time)
@@ -107,7 +111,7 @@ namespace UnityExplorer.UI.Widgets
static bool Prefix_Time_set_timeScale()
{
return !Instance.locked || Instance.settingTimeScale;
return Instance.timeScaleController.pause || !Instance.locked || Instance.settingTimeScale;
}
}
}