DebugFrame.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class DebugFrame : MonoBehaviour {
  5. [SerializeField]
  6. private UnityEngine.UI.Text mText;
  7. /// <summary>当前帧数</summary>
  8. private int nFrameCount = 60;
  9. /// <summary>统计时间</summary>
  10. private int nStartSunTime = 0;
  11. /// <summary>统计中的值</summary>
  12. private int nFrameSunIng = 0;
  13. /// <summary>渲染帧函数</summary>
  14. void Update()
  15. {
  16. if (CStaticMethod.SystemAfterTime() - nStartSunTime >= 1000)
  17. {
  18. nFrameCount = nFrameSunIng;
  19. nStartSunTime = CStaticMethod.SystemAfterTime();
  20. nFrameSunIng = 0;
  21. }
  22. else
  23. {
  24. nFrameSunIng++;
  25. }
  26. }
  27. private void LateUpdate()
  28. {
  29. Refresh();
  30. }
  31. private void Refresh()
  32. {
  33. if (nFrameCount >= 40)
  34. {
  35. mText.color = Color.white;
  36. }
  37. else if (nFrameCount >= 30)
  38. {
  39. mText.color = Color.green;
  40. }
  41. else
  42. {
  43. mText.color = Color.red;
  44. }
  45. mText.text = "" + nFrameCount;
  46. }
  47. }