Created
July 14, 2020 20:35
-
-
Save XakazukinX/2174cab8e3452a1c6a83d0a05bfaadcc to your computer and use it in GitHub Desktop.
FPSをチェックしてくれるやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
[Serializable] | |
public class FixedFpsSetting | |
{ | |
public bool useFixFps; | |
public int fixFps = 60; | |
} | |
[Serializable] | |
public class LoggingSetting | |
{ | |
public bool useLogging = true; | |
public float loggingInterval = 0.5f; | |
} | |
public class FpsTester : MonoBehaviour | |
{ | |
public float Fps { get; private set; } | |
public FixedFpsSetting fixedFpsSetting = new FixedFpsSetting(); | |
public LoggingSetting loggingSetting = new LoggingSetting(); | |
float _mPrevTime; | |
int _mFrameCount; | |
private void Awake() | |
{ | |
if (fixedFpsSetting.useFixFps) | |
{ | |
Application.targetFrameRate = fixedFpsSetting.fixFps; | |
} | |
} | |
private void Start() | |
{ | |
Fps = 60.0f; | |
_mPrevTime = 0.0f; | |
_mFrameCount = 0; | |
} | |
void Update() | |
{ | |
++_mFrameCount; | |
float diff_time = Time.realtimeSinceStartup - _mPrevTime; | |
if (loggingSetting.loggingInterval > diff_time) | |
{ | |
return; | |
} | |
Fps = ((float) _mFrameCount / diff_time); | |
if (loggingSetting.useLogging) | |
{ | |
Debug.Log(Fps); | |
} | |
_mFrameCount = 0; | |
_mPrevTime = Time.realtimeSinceStartup; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考
https://teratail.com/questions/167839