2024-01-03 01:20:51 +00:00
|
|
|
using ModAPI.Attributes;
|
|
|
|
using TheForest.Items.Inventory;
|
|
|
|
using TheForest.Utils;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace frame_limiter
|
|
|
|
{
|
|
|
|
class FrameLimiter : MonoBehaviour
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The frame limit to apply when the player is in the pause menu or loading screen.
|
2024-01-03 02:03:19 +00:00
|
|
|
* todo: make this configurable?
|
2024-01-03 01:20:51 +00:00
|
|
|
*/
|
|
|
|
private const int FrameLimit = 30;
|
|
|
|
|
|
|
|
[ExecuteOnGameStart]
|
|
|
|
private static void AddMeToScene()
|
|
|
|
{
|
|
|
|
new GameObject("__FrameLimiter__").AddComponent<FrameLimiter>();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2024-01-03 02:03:19 +00:00
|
|
|
var inventory = LocalPlayer.Inventory;
|
2024-01-03 01:20:51 +00:00
|
|
|
if (inventory == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (inventory.CurrentView)
|
|
|
|
{
|
|
|
|
case PlayerInventory.PlayerViews.Pause:
|
|
|
|
{
|
|
|
|
Application.targetFrameRate = FrameLimit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PlayerInventory.PlayerViews.Loading:
|
|
|
|
{
|
|
|
|
Application.targetFrameRate = FrameLimit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: // The frame limiter is set to the max frame rate that the user has set in the options.
|
|
|
|
{
|
|
|
|
Application.targetFrameRate = PlayerPreferences.MaxFrameRate;
|
|
|
|
break;
|
2024-01-03 02:03:19 +00:00
|
|
|
}
|
2024-01-03 01:20:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|