FpsCounter.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using UnityEngine;
  3. public class FpsCounter : MonoBehaviour
  4. {
  5. public void Awake()
  6. {
  7. if (this.num_sprite_array_ == null)
  8. {
  9. this.num_sprite_array_ = new UISprite[3];
  10. for (int i = 0; i < this.num_sprite_array_.Length; i++)
  11. {
  12. this.num_sprite_array_[i] = UTY.GetChildObject(base.gameObject, "Grid/keta" + i.ToString(), false).GetComponent<UISprite>();
  13. }
  14. }
  15. }
  16. public void Start()
  17. {
  18. this.Awake();
  19. for (int i = 1; i < this.num_sprite_array_.Length; i++)
  20. {
  21. this.num_sprite_array_[i].spriteName = this.GetSpriteName(0);
  22. this.num_sprite_array_[i].gameObject.SetActive(false);
  23. }
  24. this.back_time_ = Time.realtimeSinceStartup;
  25. }
  26. public void Update()
  27. {
  28. this.count_++;
  29. float realtimeSinceStartup = Time.realtimeSinceStartup;
  30. if (1f < realtimeSinceStartup - this.back_time_)
  31. {
  32. char[] array = this.count_.ToString().ToCharArray();
  33. Array.Reverse(array);
  34. for (int i = 0; i < this.num_sprite_array_.Length; i++)
  35. {
  36. if (array.Length <= i)
  37. {
  38. this.num_sprite_array_[i].gameObject.SetActive(false);
  39. }
  40. else
  41. {
  42. this.num_sprite_array_[i].spriteName = this.GetSpriteName(array[i]);
  43. this.num_sprite_array_[i].gameObject.SetActive(true);
  44. }
  45. }
  46. this.count_ = 0;
  47. this.back_time_ = realtimeSinceStartup;
  48. }
  49. }
  50. public string GetSpriteName(int num)
  51. {
  52. return "cmd2_fps_number" + num.ToString();
  53. }
  54. public string GetSpriteName(char num)
  55. {
  56. return "cmd2_fps_number" + num.ToString();
  57. }
  58. private UISprite[] num_sprite_array_;
  59. private float back_time_;
  60. private int count_;
  61. }