FPSDisplay.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. namespace NRKernal
  2. {
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. /// <summary> The FPS display. </summary>
  6. [RequireComponent(typeof(FPSCounter))]
  7. public class FPSDisplay : MonoBehaviour
  8. {
  9. /// <summary> The strings from 00 to 99. </summary>
  10. static string[] stringsFrom00To99 = {
  11. "00", "01", "02", "03", "04", "05", "06", "07", "08", "09",
  12. "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
  13. "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
  14. "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
  15. "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
  16. "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
  17. "60", "61", "62", "63", "64", "65", "66", "67", "68", "69",
  18. "70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
  19. "80", "81", "82", "83", "84", "85", "86", "87", "88", "89",
  20. "90", "91", "92", "93", "94", "95", "96", "97", "98", "99"
  21. };
  22. /// <summary> Gets the lowest FPS label. </summary>
  23. /// <value> The lowest FPS label. </value>
  24. public Text highestFPSLabel, averageFPSLabel, lowestFPSLabel;
  25. /// <summary> The FPS counter. </summary>
  26. FPSCounter fpsCounter;
  27. /// <summary> Awakes this object. </summary>
  28. void Awake()
  29. {
  30. fpsCounter = GetComponent<FPSCounter>();
  31. }
  32. /// <summary> Updates this object. </summary>
  33. void Update()
  34. {
  35. highestFPSLabel.text =
  36. stringsFrom00To99[Mathf.Clamp(fpsCounter.HighestFPS, 0, 99)];
  37. averageFPSLabel.text =
  38. stringsFrom00To99[Mathf.Clamp(fpsCounter.AverageFPS, 0, 99)];
  39. lowestFPSLabel.text =
  40. stringsFrom00To99[Mathf.Clamp(fpsCounter.LowestFPS, 0, 99)];
  41. }
  42. }
  43. }