54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
public class FrameRate : MonoBehaviour
|
||
{
|
||
private float deltaTime;
|
||
private float updateing;
|
||
/// <summary>
|
||
/// 帧率
|
||
/// </summary>
|
||
public float FramePerSecond { get => 1.0f / deltaTime; }
|
||
/// <summary>
|
||
/// 帧延迟
|
||
/// </summary>
|
||
public float FrameTimes { get => deltaTime * 1000f; }
|
||
|
||
private FrameRate _FrameRate;
|
||
private GameObject _GameObject;
|
||
public FrameRate()
|
||
{
|
||
|
||
}
|
||
|
||
public FrameRate UpdateFrame()
|
||
{
|
||
GameObject fr = new GameObject();
|
||
_GameObject = fr;
|
||
_GameObject.name = "FrameRateCalculator";
|
||
_FrameRate = _GameObject.AddComponent<FrameRate>();
|
||
return _FrameRate;
|
||
}
|
||
|
||
void LateUpdate()
|
||
{
|
||
deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;
|
||
}
|
||
|
||
bool activeCamera;
|
||
float fps, ft;
|
||
void OnGUI()
|
||
{
|
||
updateing += Time.deltaTime;
|
||
if (updateing > 0.5f) {
|
||
updateing = 0;
|
||
fps = FramePerSecond;
|
||
ft = FrameTimes;
|
||
}
|
||
|
||
string msg = string.Format("ID:{0}\nFPS:{2:f0}\nPlayers:{1}\nRenderer:{3}", MyPlayer.Me != null ? MyPlayer.Me.syncid : -1, MyPlayer.Me != null ? MyPlayer.players.Count : 0, fps, GUIManager.Renderered ? "ON" : "OFF");
|
||
GUI.Label(new Rect(22, 22, 200, 40), msg, new GUIStyle() { font = GameManager.Instance._font, normal = new GUIStyleState() { textColor = Color.black }, fontSize = 22 });
|
||
GUI.Label(new Rect(20, 20, 200, 40), msg, new GUIStyle() { font = GameManager.Instance._font, normal = new GUIStyleState() { textColor = Color.white }, fontSize = 22 });
|
||
}
|
||
} |