SamsonGame/Assets/Sources/Feel/MMTools/Tools/MMPerformance/MMFPSUnlock.cs

46 lines
1.6 KiB
C#
Raw Normal View History

2021-12-29 20:50:11 +03:00
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
namespace MoreMountains.Tools
{
/// <summary>
/// Add this component to any object and it'll set the target frame rate and vsync count. Note that vsync count must be 0 for the target FPS to work.
/// </summary>
[AddComponentMenu("More Mountains/Tools/Performance/MMFPSUnlock")]
public class MMFPSUnlock : MonoBehaviour
{
[MMInformation("Add this component to any object and it'll set the target frame rate and vsync count. Note that vsync count must be 0 for the target FPS to work.", MoreMountains.Tools.MMInformationAttribute.InformationType.Info, false)]
/// the target FPS you want the game to run at
public int TargetFPS;
[Range(0,2)]
/// whether vsync should be enabled or not (on a 60Hz screen, 1 : 60fps, 2 : 30fps, 0 : don't wait for vsync)
public int VSyncCount = 0;
/// <summary>
/// On start we change our target fps and vsync settings
/// </summary>
protected virtual void Start()
{
UpdateSettings();
}
/// <summary>
/// When a value gets changed in the editor, we update our settings
/// </summary>
protected virtual void OnValidate()
{
UpdateSettings();
}
/// <summary>
/// Updates the target frame rate value and vsync count setting
/// </summary>
protected virtual void UpdateSettings()
{
QualitySettings.vSyncCount = VSyncCount;
Application.targetFrameRate = TargetFPS;
}
}
}