-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
257 additions
and
1 deletion.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class FpsCounter | ||
{ | ||
// フレーム数をカウント | ||
private int frameCount = 0; | ||
// 計測開始時間 | ||
private float elapsedTime = 0f; | ||
// FPS値 | ||
private float fps = 0f; | ||
// 更新頻度(FPSを計算する間隔) | ||
public float updateInterval = 0.5f; | ||
|
||
public void OnUpdate() | ||
{ | ||
// 経過時間をカウント | ||
elapsedTime += Time.deltaTime; | ||
frameCount++; | ||
|
||
// 一定間隔でFPSを計算 | ||
if (elapsedTime >= updateInterval) | ||
{ | ||
// FPSを計算 | ||
fps = frameCount / elapsedTime; | ||
|
||
// カウンタをリセット | ||
frameCount = 0; | ||
elapsedTime = 0f; | ||
} | ||
} | ||
|
||
// FPSを取得するメソッド | ||
public float GetFps() | ||
{ | ||
return fps; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using TMPro; | ||
using UniRx; | ||
using UnityEngine; | ||
|
||
public class FpsCounterUiPresenter : MonoBehaviour | ||
{ | ||
[SerializeField] | ||
private TMP_Text fpsCounter_GUIText = null; | ||
|
||
private FpsCounter fpsCounter = new FpsCounter(); | ||
private IDisposable disposable = null; | ||
|
||
private float latestViewFps = -1f; | ||
|
||
private void Start() | ||
{ | ||
disposable = Observable.EveryUpdate() | ||
.Subscribe(_ => | ||
{ | ||
fpsCounter.OnUpdate(); | ||
|
||
float fps = fpsCounter.GetFps(); | ||
|
||
if (fps != latestViewFps) | ||
{ | ||
fpsCounter_GUIText.text = fps.ToString("F1"); | ||
|
||
latestViewFps = fps; | ||
} | ||
}); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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