mirror of
https://github.com/originalnicodr/CinematicUnityExplorer.git
synced 2026-10-10 13:03:15 +08:00
158 lines
4.4 KiB
C#
158 lines
4.4 KiB
C#
using UnityExplorer.Config;
|
|
using UnityExplorer.UI;
|
|
using UnityExplorer.UI.Panels;
|
|
using UnityExplorer.UI.Widgets;
|
|
using UniverseLib.Input;
|
|
#if CPP
|
|
#if UNHOLLOWER
|
|
using UnhollowerRuntimeLib;
|
|
#else
|
|
using Il2CppInterop.Runtime.Injection;
|
|
#endif
|
|
#endif
|
|
using System;
|
|
|
|
|
|
namespace UnityExplorer
|
|
{
|
|
public class ExplorerBehaviour : MonoBehaviour
|
|
{
|
|
internal static ExplorerBehaviour Instance { get; private set; }
|
|
|
|
#if CPP
|
|
public ExplorerBehaviour(System.IntPtr ptr) : base(ptr) { }
|
|
#endif
|
|
|
|
internal static void Setup()
|
|
{
|
|
#if CPP
|
|
ClassInjector.RegisterTypeInIl2Cpp<ExplorerBehaviour>();
|
|
#endif
|
|
|
|
GameObject obj = new("ExplorerBehaviour");
|
|
DontDestroyOnLoad(obj);
|
|
obj.hideFlags = HideFlags.HideAndDontSave;
|
|
Instance = obj.AddComponent<ExplorerBehaviour>();
|
|
}
|
|
|
|
internal void Update()
|
|
{
|
|
ExplorerCore.Update();
|
|
}
|
|
|
|
// For editor, to clean up objects
|
|
|
|
internal void OnDestroy()
|
|
{
|
|
OnApplicationQuit();
|
|
}
|
|
|
|
internal bool quitting;
|
|
|
|
internal void OnApplicationQuit()
|
|
{
|
|
if (quitting) return;
|
|
quitting = true;
|
|
|
|
TryDestroy(UIManager.UIRoot?.transform.root.gameObject);
|
|
|
|
TryDestroy((typeof(Universe).Assembly.GetType("UniverseLib.UniversalBehaviour")
|
|
.GetProperty("Instance", BindingFlags.Static | BindingFlags.NonPublic)
|
|
.GetValue(null, null)
|
|
as Component).gameObject);
|
|
|
|
TryDestroy(this.gameObject);
|
|
}
|
|
|
|
internal void TryDestroy(GameObject obj)
|
|
{
|
|
try
|
|
{
|
|
if (obj)
|
|
Destroy(obj);
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
|
|
// Cinematic stuff
|
|
|
|
public class KeypressListener : MonoBehaviour
|
|
{
|
|
internal static KeypressListener Instance { get; private set; }
|
|
|
|
#if CPP
|
|
public KeypressListener(System.IntPtr ptr) : base(ptr) { }
|
|
#endif
|
|
bool frameSkip;
|
|
|
|
internal static void Setup()
|
|
{
|
|
#if CPP
|
|
ClassInjector.RegisterTypeInIl2Cpp<KeypressListener>();
|
|
#endif
|
|
|
|
GameObject obj = new("KeypressListener");
|
|
DontDestroyOnLoad(obj);
|
|
obj.hideFlags = HideFlags.HideAndDontSave;
|
|
Instance = obj.AddComponent<KeypressListener>();
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
// Continous checks and actions
|
|
stopFrameSkip();
|
|
maybeForcePause();
|
|
UIManager.GetPanel<UnityExplorer.UI.Panels.Misc>(UIManager.Panels.Misc).MaybeTakeScreenshot();
|
|
|
|
if (InputManager.GetKeyDown(ConfigManager.Pause.Value))
|
|
{
|
|
UIManager.GetTimeScaleWidget().PauseToggle();
|
|
}
|
|
|
|
// FrameSkip
|
|
if (InputManager.GetKeyDown(ConfigManager.Frameskip.Value))
|
|
{
|
|
if (UIManager.GetTimeScaleWidget().IsPaused()) {
|
|
UIManager.GetTimeScaleWidget().PauseToggle();
|
|
frameSkip = true;
|
|
}
|
|
}
|
|
|
|
if (InputManager.GetKeyDown(ConfigManager.Screenshot.Value))
|
|
{
|
|
UIManager.GetPanel<UnityExplorer.UI.Panels.Misc>(UIManager.Panels.Misc).screenshotStatus = UnityExplorer.UI.Panels.Misc.ScreenshotState.TurnOffUI;
|
|
}
|
|
|
|
if (InputManager.GetKeyDown(ConfigManager.HUD_Toggle.Value))
|
|
{
|
|
UIManager.GetPanel<UnityExplorer.UI.Panels.Misc>(UIManager.Panels.Misc).ToggleHUDElements();
|
|
}
|
|
|
|
if (InputManager.GetKeyDown(ConfigManager.Freecam_Toggle.Value))
|
|
{
|
|
FreeCamPanel.StartStopButton_OnClick();
|
|
}
|
|
|
|
if (InputManager.GetKeyDown(ConfigManager.Block_Freecam_Movement.Value))
|
|
{
|
|
FreeCamPanel.blockFreecamMovementToggle.isOn = !FreeCamPanel.blockFreecamMovementToggle.isOn;
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|