Created
December 17, 2016 14:20
-
-
Save anonymous/e18c54bc06c96e3224e4705546f99444 to your computer and use it in GitHub Desktop.
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
/* | |
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment