using System;
using System.Collections.Generic;
using UnityEngine;
public class Debugger : MonoBehaviour
{
void Start()
{
timeleft = updateInterval;
}
void Update()
{
UpdateUsed();
UpdateFPS();
}
//Memory
private string sUserMemory;
private string s;
public bool OnMemoryGUI;
private uint MonoUsedM;
private uint AllMemory;
[Range(0, 100)]
public int MaxMonoUsedM = 50;
[Range(0, 400)]
public int MaxAllMemory = 200;
void UpdateUsed()
{
sUserMemory = "";
MonoUsedM = Profiler.GetMonoUsedSize() / 1000000;
AllMemory = Profiler.GetTotalAllocatedMemory() / 1000000;
sUserMemory += "MonoUsed:" + MonoUsedM + "M" + "\n";
sUserMemory += "AllMemory:" + AllMemory + "M" + "\n";
sUserMemory += "UnUsedReserved:" + Profiler.GetTotalUnusedReservedMemory() / 1000000 + "M" + "\n";
s = "";
s += " MonoHeap:" + Profiler.GetMonoHeapSize() / 1000 + "k";
s += " MonoUsed:" + Profiler.GetMonoUsedSize() / 1000 + "k";
s += " Allocated:" + Profiler.GetTotalAllocatedMemory() / 1000 + "k";
s += " Reserved:" + Profiler.GetTotalReservedMemory() / 1000 + "k";
s += " UnusedReserved:" + Profiler.GetTotalUnusedReservedMemory() / 1000 + "k";
s += " UsedHeap:" + Profiler.usedHeapSize / 1000 + "k";
}
//FPS
float updateInterval = 0.5f;
private float accum = 0.0f;
private float frames = 0;
private float timeleft;
private float fps;
private string FPSAAA;
[Range(0, 150)]
public int MaxFPS;
void UpdateFPS()
{
timeleft -= Time.deltaTime;
accum += Time.timeScale / Time.deltaTime;
++frames;
if (timeleft <= 0.0)
{
fps = accum / frames;
FPSAAA = "FPS: " + fps.ToString("f2");
timeleft = updateInterval;
accum = 0.0f;
frames = 0;
}
}
void OnGUI()
{
if (OnMemoryGUI)
{
GUI.color = new Color(1, 0, 0);
GUI.Label(new Rect(10, 10, 200, 60), sUserMemory);
GUI.Label(new Rect(10, 60, 100, 30), FPSAAA);
if (MonoUsedM > MaxMonoUsedM)
{
GUI.backgroundColor = new Color(1, 0, 0);
GUI.Button(new Rect(0, 0, 1024, 1024), "MonoUsedM Waming!!内存不足");
}
if (AllMemory > MaxAllMemory)
{
GUI.backgroundColor = new Color(1, 0, 1);
GUI.Button(new Rect(0, 0, 1024, 1024), "AllMemory Waming!!内存堪忧");
}
if (fps > MaxFPS)
{
GUI.backgroundColor = new Color(1, 0.4f, 0.5f);
GUI.Button(new Rect(0, 0, 1024, 1024), "FPS Waming!!");
}
}
}
}
相关文章
- 无废话Android之android下junit测试框架配置、保存文件到手机内存、android下文件访问的权限、保存文件到SD卡、获取SD卡大小、使用SharedPreferences进行数据存储、使用Pull解析器操作XML文件、android下操作sqlite数据库和事务(2)
- MFC下获取系统内存和当前进程的内存使用情况
- 我将通过下面的脚本获取xml文件,但是如何在c#页面上保存和访问呢?
- 提取Unity游戏资源和脚本
- Unity3D中脚本的执行顺序和编译顺序
- Shell脚本监控CPU、内存和硬盘利用率
- PowerShell包含另一个脚本文件和获取当前脚本所在目录的方法例子
- android 手机获取root权限_获取刷入模块_MIUI_android7~android12实践/A1内存管理和钢铁后台效果测评/root省电调度&性能调度
- 如何通过单个NPM脚本获取node-sass监视和实时重新加载?
- android设备的内存空间(RAM)总空间和可用空间大小的获取以及一些思考