using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FrameRate : MonoBehaviour
{
private float deltaTime;
private float updateing;
///
/// 帧率
///
public float FramePerSecond { get => 1.0f / deltaTime; }
///
/// 帧延迟
///
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();
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 });
}
}