1
0
mirror of https://github.com/originalnicodr/CinematicUnityExplorer.git synced 2026-10-10 21:13:15 +08:00

Added Frameskip, and fixed the pause key not working.

This commit is contained in:
originalnicodr
2024-01-13 15:46:19 -03:00
parent d70fc10ea5
commit 6ad2554225
2 changed files with 34 additions and 14 deletions
+33 -13
View File
@@ -76,39 +76,59 @@ namespace UnityExplorer
// Cinematic stuff
public class PauseListener : MonoBehaviour
public class KeypressListener : MonoBehaviour
{
internal static PauseListener Instance { get; private set; }
internal static KeypressListener Instance { get; private set; }
#if CPP
public PauseListener(System.IntPtr ptr) : base(ptr) { }
public KeypressListener(System.IntPtr ptr) : base(ptr) { }
#endif
public static TimeScaleWidget timeScaleWidget;
bool frameSkip;
internal static void Setup()
{
#if CPP
ClassInjector.RegisterTypeInIl2Cpp<PauseListener>();
ClassInjector.RegisterTypeInIl2Cpp<KeypressListener>();
#endif
GameObject obj = new("PauseListener");
GameObject obj = new("KeypressListener");
DontDestroyOnLoad(obj);
obj.hideFlags = HideFlags.HideAndDontSave;
Instance = obj.AddComponent<PauseListener>();
timeScaleWidget = UIManager.GetTimeScaleWidget();
Instance = obj.AddComponent<KeypressListener>();
}
public void Update()
{
// Continous checks and actions
stopFrameSkip();
maybeForcePause();
if (InputManager.GetKeyDown(KeyCode.Pause))
{
timeScaleWidget.PauseToggle();
UIManager.GetTimeScaleWidget().PauseToggle();
}
// Force pause no matter the game timescale changes.
if (timeScaleWidget.IsPaused() && Time.timeScale != 0) {
timeScaleWidget.SetTimeScale(0f);
// FrameSkip
if (InputManager.GetKeyDown(KeyCode.PageDown))
{
if (UIManager.GetTimeScaleWidget().IsPaused()) {
UIManager.GetTimeScaleWidget().PauseToggle();
frameSkip = true;
}
}
}
void stopFrameSkip(){
if (frameSkip && !UIManager.GetTimeScaleWidget().IsPaused()){
frameSkip = false;
UIManager.GetTimeScaleWidget().PauseToggle();
}
}
void maybeForcePause(){
// Force pause no matter the game timescale changes
if (UIManager.GetTimeScaleWidget().IsPaused() && Time.timeScale != 0) {
UIManager.GetTimeScaleWidget().SetTimeScale(0f);
}
}
}