184 lines
4.6 KiB
C#
184 lines
4.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace CTS
|
|
{
|
|
public class CTSFps : MonoBehaviour
|
|
{
|
|
private const string cFormat = "FPS {0}, MS {1:0.00}";
|
|
|
|
private const float cMeasurePeriod = 1f;
|
|
|
|
private float m_currentFps;
|
|
|
|
private float m_currentMs;
|
|
|
|
private float m_fpsAccumulator;
|
|
|
|
private float m_fpsNextPeriod;
|
|
|
|
public string m_CTSVersion;
|
|
|
|
public string m_OS;
|
|
|
|
public string m_deviceName;
|
|
|
|
public string m_deviceType;
|
|
|
|
public string m_deviceModel;
|
|
|
|
public string m_platform;
|
|
|
|
public string m_processor;
|
|
|
|
public string m_ram;
|
|
|
|
public string m_gpu;
|
|
|
|
public string m_gpuDevice;
|
|
|
|
public string m_gpuVendor;
|
|
|
|
public string m_gpuSpec;
|
|
|
|
public string m_gpuRam;
|
|
|
|
public string m_gpuCapabilities;
|
|
|
|
public string m_screenInfo;
|
|
|
|
public string m_quality;
|
|
|
|
public Text m_fpsText;
|
|
|
|
public Text m_CTSVersionText;
|
|
|
|
public Text m_OSText;
|
|
|
|
public Text m_deviceText;
|
|
|
|
public Text m_systemText;
|
|
|
|
public Text m_gpuText;
|
|
|
|
public Text m_gpuCapabilitiesText;
|
|
|
|
public Text m_screenInfoText;
|
|
|
|
public int FPS => (int)m_currentFps;
|
|
|
|
private void Start()
|
|
{
|
|
m_fpsNextPeriod = Time.realtimeSinceStartup + 1f;
|
|
try
|
|
{
|
|
m_CTSVersion = "CTS v" + CTSConstants.MajorVersion + "." + CTSConstants.MinorVersion + "." + CTSConstants.PatchVersion + ", Unity v" + Application.unityVersion;
|
|
m_deviceName = SystemInfo.deviceName;
|
|
m_deviceType = SystemInfo.deviceType.ToString();
|
|
m_OS = SystemInfo.operatingSystem;
|
|
m_platform = Application.platform.ToString();
|
|
m_processor = SystemInfo.processorType + " - " + SystemInfo.processorCount + " cores";
|
|
m_gpu = SystemInfo.graphicsDeviceName;
|
|
m_gpuDevice = SystemInfo.graphicsDeviceType.ToString() + " - " + SystemInfo.graphicsDeviceVersion;
|
|
m_gpuVendor = SystemInfo.graphicsDeviceVendor;
|
|
m_gpuRam = SystemInfo.graphicsMemorySize.ToString();
|
|
m_gpuCapabilities = m_gpuCapabilities + "TA: " + SystemInfo.supports2DArrayTextures;
|
|
m_gpuCapabilities = m_gpuCapabilities + ", MT: " + SystemInfo.maxTextureSize;
|
|
m_gpuCapabilities = m_gpuCapabilities + ", NPOT: " + SystemInfo.npotSupport;
|
|
m_gpuCapabilities = m_gpuCapabilities + ", RTC: " + SystemInfo.supportedRenderTargetCount;
|
|
m_gpuCapabilities = m_gpuCapabilities + ", CT: " + SystemInfo.copyTextureSupport;
|
|
int graphicsShaderLevel = SystemInfo.graphicsShaderLevel;
|
|
if (graphicsShaderLevel >= 10 && graphicsShaderLevel <= 99)
|
|
{
|
|
int num = (graphicsShaderLevel /= 10);
|
|
m_gpuSpec = "SM: " + num + "." + graphicsShaderLevel / 10;
|
|
}
|
|
else
|
|
{
|
|
m_gpuSpec = "SM: N/A";
|
|
}
|
|
int graphicsMemorySize = SystemInfo.graphicsMemorySize;
|
|
if (graphicsMemorySize > 0)
|
|
{
|
|
m_gpuSpec = m_gpuSpec + ", VRAM: " + graphicsMemorySize + " MB";
|
|
}
|
|
else
|
|
{
|
|
m_gpuSpec = m_gpuSpec + ", VRAM: " + graphicsMemorySize + " N/A";
|
|
}
|
|
int systemMemorySize = SystemInfo.systemMemorySize;
|
|
if (systemMemorySize > 0)
|
|
{
|
|
m_ram = systemMemorySize.ToString();
|
|
}
|
|
else
|
|
{
|
|
m_ram = "N/A";
|
|
}
|
|
Resolution currentResolution = Screen.currentResolution;
|
|
m_screenInfo = currentResolution.width + "x" + currentResolution.height + " @" + currentResolution.refreshRate + " Hz [window size: " + Screen.width + "x" + Screen.height;
|
|
float dpi = Screen.dpi;
|
|
if (dpi > 0f)
|
|
{
|
|
m_screenInfo = m_screenInfo + ", DPI: " + dpi + "]";
|
|
}
|
|
else
|
|
{
|
|
m_screenInfo += "]";
|
|
}
|
|
m_deviceModel = SystemInfo.deviceModel;
|
|
m_quality = QualitySettings.GetQualityLevel().ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.Log("Problem getting system metrics : " + ex.Message);
|
|
}
|
|
if (m_CTSVersionText != null)
|
|
{
|
|
m_CTSVersionText.text = m_CTSVersion;
|
|
}
|
|
if (m_OSText != null)
|
|
{
|
|
m_OSText.text = m_OS;
|
|
}
|
|
if (m_deviceText != null)
|
|
{
|
|
m_deviceText.text = m_deviceName + ", " + m_platform + ", " + m_deviceType;
|
|
}
|
|
if (m_systemText != null)
|
|
{
|
|
m_systemText.text = m_deviceModel + ", " + m_processor + ", " + m_ram + " GB";
|
|
}
|
|
if (m_gpuText != null)
|
|
{
|
|
m_gpuText.text = m_gpu + ", " + m_gpuSpec + ", QUAL: " + m_quality;
|
|
}
|
|
if (m_gpuCapabilitiesText != null)
|
|
{
|
|
m_gpuCapabilitiesText.text = m_gpuDevice + ", " + m_gpuCapabilities;
|
|
}
|
|
if (m_screenInfoText != null)
|
|
{
|
|
m_screenInfoText.text = m_screenInfo;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
m_fpsAccumulator += 1f;
|
|
if (Time.realtimeSinceStartup > m_fpsNextPeriod)
|
|
{
|
|
m_currentFps = m_fpsAccumulator / 1f;
|
|
m_currentMs = 1000f / m_currentFps;
|
|
m_fpsAccumulator = 0f;
|
|
m_fpsNextPeriod = Time.realtimeSinceStartup + 1f;
|
|
if (m_fpsText != null)
|
|
{
|
|
m_fpsText.text = $"FPS {m_currentFps}, MS {m_currentMs:0.00}";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|