-
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.
Updated Unity to 2018.2.5f1, added FPS counter
- Loading branch information
1 parent
9500bc2
commit 5b0c9ad
Showing
4 changed files
with
155 additions
and
2 deletions.
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
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,53 @@ | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
public class FPS : MonoBehaviour | ||
{ | ||
#region Public Fields | ||
|
||
public float UpdateInterval = 0.5F; | ||
|
||
#endregion Public Fields | ||
|
||
#region Private Fields | ||
|
||
private float _accumulatedTime = 0; | ||
private int _frame; | ||
private float _timeLeft; | ||
|
||
#endregion Private Fields | ||
|
||
#region Private Methods | ||
|
||
private void Start() | ||
{ | ||
_timeLeft = UpdateInterval; | ||
} | ||
|
||
private void Update() | ||
{ | ||
_timeLeft -= Time.deltaTime; | ||
_accumulatedTime += Time.timeScale / Time.deltaTime; | ||
++_frame; | ||
|
||
if (_timeLeft <= 0.0) | ||
{ | ||
float fps = _accumulatedTime / _frame; | ||
gameObject.GetComponent<Text>().text = System.String.Format("{0:F0} FPS", fps); | ||
|
||
if (fps < 30) | ||
gameObject.GetComponent<Text>().material.color = Color.yellow; | ||
else | ||
if (fps < 10) | ||
gameObject.GetComponent<Text>().material.color = Color.red; | ||
else | ||
gameObject.GetComponent<Text>().material.color = Color.green; | ||
|
||
_timeLeft = UpdateInterval; | ||
_accumulatedTime = 0.0F; | ||
_frame = 0; | ||
} | ||
} | ||
|
||
#endregion Private Methods | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
m_EditorVersion: 2018.2.4f1 | ||
m_EditorVersion: 2018.2.5f1 |