50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
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.
|
|
* todo: make this configurable?
|
|
*/
|
|
private const int FrameLimit = 30;
|
|
|
|
[ExecuteOnGameStart]
|
|
private static void AddMeToScene()
|
|
{
|
|
new GameObject("__FrameLimiter__").AddComponent<FrameLimiter>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
var 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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |