tf-frame-limiter/FrameLimiter.cs

51 lines
1.4 KiB
C#
Raw Normal View History

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.
*/
private const int FrameLimit = 30;
[ExecuteOnGameStart]
private static void AddMeToScene()
{
new GameObject("__FrameLimiter__").AddComponent<FrameLimiter>();
}
private void Update()
{
PlayerInventory inventory = LocalPlayer.Inventory;
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;
}
}
}
}
}