Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ClientSettings : MonoBehaviour
- {
- public enum TargetFrameRate { Limit_30 = 30, Limit_60 = 60, Limit_120 = 120,Limit_144 = 144, Limit_240 = 240, Unlimited = 1337}
- public TargetFrameRate frameRate = TargetFrameRate.Unlimited;
- public enum VSyncLevels { disabled, MonitorRefreshRate, HalfMonitorRefreshRate }
- public VSyncLevels vSync = VSyncLevels.MonitorRefreshRate;
- public bool ShowFPS = false;
- private string fpsLabel;
- private float count;
- private int hideOffset = 0;
- private Color fpsColor = Color.green;
- IEnumerator Start()
- {
- QualitySettings.vSyncCount = (int)vSync;
- Application.targetFrameRate = (int)frameRate;
- float maxFPS = 0f;
- float minFPS = 1337f;
- GUI.depth = 2;
- QualitySettings.vSyncCount = (int)vSync;
- Application.targetFrameRate = (int)frameRate;
- while (true)
- {
- if (Time.timeScale == 1 && ShowFPS)
- {
- hideOffset = 0;
- yield return new WaitForSeconds(0.1f);
- count = (1 / Time.deltaTime);
- if (count > maxFPS) maxFPS = count;
- if (count < minFPS) minFPS = count;
- string target = "(" + frameRate.ToString() + ")";
- if (frameRate == TargetFrameRate.Unlimited) target = "";
- fpsLabel = "" + Mathf.Round(count) + target + "\nmin:" + Mathf.Round(minFPS) +"\nmax:"+ Mathf.Round(maxFPS);
- //Color Changing in relation to fps count
- if (Mathf.Round(count) < 30) fpsColor = Color.red;
- if (Mathf.Round(count) < 59 && Mathf.Round(count) >= 30) fpsColor = Color.yellow;
- if(Mathf.Round(count) >= 60) fpsColor = Color.green;
- }
- else
- {
- //Reset and hide box outside the screen
- fpsLabel = "";
- maxFPS = 0f;
- minFPS = 1337f;
- hideOffset = -500;
- }
- yield return new WaitForSeconds(0.5f);
- }
- }
- void OnGUI()
- {
- GUI.color = fpsColor;
- GUI.Box(new Rect(hideOffset + 1, 1, 125, 50), fpsLabel);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement