123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using UnityEngine;
- namespace FirstGearGames.Utilities.Maths
- {
- public class FrameRateCalculator
- {
- #region Private.
-
-
-
- private float _timePassed = 0f;
-
-
-
- private float _frames = 0;
- #endregion
- #region Const.
-
-
-
- private const int RESET_FRAME_COUNT = 60;
-
-
-
- private const float CALCULATION_SLICE_PERCENT = 0.7f;
- #endregion
-
-
-
-
- public int GetIntFrameRate()
- {
- return Mathf.CeilToInt((_frames / _timePassed));
- }
-
-
-
-
- public float GetFloatFrameRate()
- {
- return (_frames / _timePassed);
- }
-
-
-
- public bool Update(float unscaledDeltaTime)
- {
- _timePassed += unscaledDeltaTime;
- _frames++;
- if (_frames > RESET_FRAME_COUNT)
- {
- _frames *= CALCULATION_SLICE_PERCENT;
- _timePassed *= CALCULATION_SLICE_PERCENT;
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
|