1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using UnityEngine;
- using System.Collections;
- namespace Engine.Component
- {
- /// <summary>统计帧频</summary>
- public class FPSComponent : BaseComponent
- {
- /// <summary>当前帧数</summary>
- private int nFrameCt = 60;
- /// <summary>统计时间</summary>
- private int nStartTime = 0;
- /// <summary>统计中的值</summary>
- private int nFrameIng = 0;
- /// <summary>渲染帧函数</summary>
- void Update()
- {
- if (CStaticMethod.SystemAfterTime () - nStartTime >= 1000)
- {
- nFrameCt = nFrameIng;
- nStartTime = CStaticMethod.SystemAfterTime ();
- nFrameIng = 0;
- }
- else
- {
- nFrameIng++;
- }
- }
- void OnGUI()
- {
- GUIStyle testStyle = new GUIStyle();
- testStyle.normal.background = null;
- if (nFrameCt >= 40)
- {
- testStyle.normal.textColor = Color.white;
- }
- else if (nFrameCt >= 30)
- {
- testStyle.normal.textColor = Color.green;
- }
- else {
- testStyle.normal.textColor = Color.red;
- }
- testStyle.fontSize = 30;
- GUI.Label(new Rect(10, 10, 200, 60), "frame:" + nFrameCt, testStyle);
-
- }
- }
- }
|