Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
NYSL License ご自由に
Unity5.3ぐらいで動作します。
*/
using UnityEngine;
using UnityEngine.UI;
using System;
/// <summary>
/// デバッグ用 FSPを表示するだけ
/// </summary>
public class FPSCalc : MonoBehaviour
{
private int _frameCount;
private float _prevTime;
// uGUIのテキスト格納用 (使わないなら無しでok)
public Text Text;
// FPSをDebugLogで出力するかどうか。 使うとログが荒れるけど正確な値が見られる。
public bool UseFpsToDebugLog;
/// <summary>
/// 初期化処理
/// </summary>
void Start()
{
_frameCount = 0;
_prevTime = 0.0f;
}
void Update()
{
++_frameCount;
float time = Time.realtimeSinceStartup - _prevTime;
// 0.5秒ごとに変更
if (time >= 0.5f)
{
if (UseFpsToDebugLog)
Debug.Log(_frameCount / time + "fps");
if (Text)
//少数2位で四捨五入
Text.text = Math.Round(_frameCount / time, 1, MidpointRounding.AwayFromZero) + "fps";
//フレームカウントを戻して秒数を更新
_frameCount = 0;
_prevTime = Time.realtimeSinceStartup;
}
}
}
@Slime-hatena

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.