修改水
This commit is contained in:
@@ -2,59 +2,56 @@
|
||||
using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
|
||||
namespace Obi.Samples
|
||||
[RequireComponent(typeof(Text))]
|
||||
public class FPSDisplay : MonoBehaviour
|
||||
{
|
||||
[RequireComponent(typeof(Text))]
|
||||
public class FPSDisplay : MonoBehaviour
|
||||
public float updateInterval = 0.5f;
|
||||
|
||||
public bool showMedian = false;
|
||||
public float medianLearnrate = 0.05f;
|
||||
|
||||
private float accum = 0; // FPS accumulated over the interval
|
||||
private int frames = 0; // Frames drawn over the interval
|
||||
private float timeleft; // Left time for current interval
|
||||
private float currentFPS = 0;
|
||||
|
||||
private float median = 0;
|
||||
private float average = 0;
|
||||
|
||||
public float CurrentFPS{
|
||||
get { return currentFPS; }
|
||||
}
|
||||
|
||||
public float FPSMedian
|
||||
{
|
||||
public float updateInterval = 0.5f;
|
||||
get { return median; }
|
||||
}
|
||||
|
||||
public bool showMedian = false;
|
||||
public float medianLearnrate = 0.05f;
|
||||
public float FPSAverage
|
||||
{
|
||||
get { return average; }
|
||||
}
|
||||
|
||||
private float accum = 0; // FPS accumulated over the interval
|
||||
private int frames = 0; // Frames drawn over the interval
|
||||
private float timeleft; // Left time for current interval
|
||||
private float currentFPS = 0;
|
||||
Text uguiText;
|
||||
|
||||
private float median = 0;
|
||||
private float average = 0;
|
||||
void Start()
|
||||
{
|
||||
uguiText = GetComponent<Text>();
|
||||
timeleft = updateInterval;
|
||||
}
|
||||
|
||||
public float CurrentFPS
|
||||
{
|
||||
get { return currentFPS; }
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
// Timing inside the editor is not accurate. Only use in actual build.
|
||||
|
||||
public float FPSMedian
|
||||
{
|
||||
get { return median; }
|
||||
}
|
||||
|
||||
public float FPSAverage
|
||||
{
|
||||
get { return average; }
|
||||
}
|
||||
|
||||
Text uguiText;
|
||||
|
||||
void Start()
|
||||
{
|
||||
uguiText = GetComponent<Text>();
|
||||
timeleft = updateInterval;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Timing inside the editor is not accurate. Only use in actual build.
|
||||
|
||||
//#if !UNITY_EDITOR
|
||||
//#if !UNITY_EDITOR
|
||||
|
||||
timeleft -= Time.deltaTime;
|
||||
accum += Time.timeScale / Time.deltaTime;
|
||||
accum += Time.timeScale/Time.deltaTime;
|
||||
++frames;
|
||||
|
||||
|
||||
// Interval ended - update GUI text and start new interval
|
||||
if (timeleft <= 0.0)
|
||||
if( timeleft <= 0.0)
|
||||
{
|
||||
currentFPS = accum / frames;
|
||||
|
||||
@@ -63,19 +60,18 @@ namespace Obi.Samples
|
||||
|
||||
// display two fractional digits (f2 format)
|
||||
float fps = showMedian ? median : currentFPS;
|
||||
uguiText.text = System.String.Format("{0:F2} FPS ({1:F1} ms)", fps, 1000.0f / fps);
|
||||
uguiText.text = System.String.Format("{0:F2} FPS ({1:F1} ms)", fps, 1000.0f / fps);
|
||||
|
||||
timeleft = updateInterval;
|
||||
accum = 0.0F;
|
||||
frames = 0;
|
||||
}
|
||||
//#endif
|
||||
}
|
||||
//#endif
|
||||
}
|
||||
|
||||
public void ResetMedianAndAverage()
|
||||
{
|
||||
median = 0;
|
||||
average = 0;
|
||||
}
|
||||
public void ResetMedianAndAverage()
|
||||
{
|
||||
median = 0;
|
||||
average = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user