Unity简易内存查找

xiaoxiao2021-02-28  3

using UnityEngine; using System.Collections; using UnityEngine.Profiling; public class MyDebugg : MonoBehaviour { // Use this for initialization private System.DateTime firetime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); private GUIStyle bb; [Range(0.1f,60)] public float UpdateTime = 1; [Range(0,150)] public int fontsize = 40; public Color fontcolor = new Color(0, 0, 0); void Awake() { bb = new GUIStyle(); bb.normal.background = null; //这是设置背景填充的 bb.normal.textColor = fontcolor; //设置字体颜色的 bb.fontSize = fontsize; //当然,这是字体颜色 } // Update is called once per frame void Update() { } float TotalReservedMemory = 0; float TotalAllocatedMemory = 0; float TotalnoMonoAllocatedMemory = 0; float TotalUnusedReservedMemory = 0; float MonoHeapSize = 0; float MonoUsedSize = 0; private void OnGUI() { System.TimeSpan dic = System.DateTime.UtcNow - firetime; if (dic.TotalSeconds > UpdateTime) { firetime = System.DateTime.UtcNow; TotalReservedMemory = Profiler.GetTotalReservedMemory() / (float)1000000 ; TotalAllocatedMemory = Profiler.GetTotalAllocatedMemory() / (float)1000000 ; TotalUnusedReservedMemory = Profiler.GetTotalUnusedReservedMemory() / (float)1000000 ; MonoHeapSize = Profiler.GetMonoHeapSize() / (float)1000000 ; MonoUsedSize = Profiler.GetMonoUsedSize() / (float)1000000 ; TotalnoMonoAllocatedMemory = TotalAllocatedMemory - MonoUsedSize; bb.normal.textColor = fontcolor; bb.fontSize = fontsize; } GUI.Label(new Rect(0, 0, 100, 40), "总内存: " + TotalReservedMemory + "MB", bb); GUI.Label(new Rect(0, fontsize, 100, 40), "已占用内存: " + TotalAllocatedMemory + "MB", bb); GUI.Label(new Rect(0, fontsize*2, 100, 40), "除去Mono堆内存已占用内存: " + TotalnoMonoAllocatedMemory + "MB", bb); GUI.Label(new Rect(0, fontsize*3, 100, 40), "空闲中内存: " + TotalUnusedReservedMemory + "MB", bb); GUI.Label(new Rect(0, fontsize*4, 100, 40), "总Mono堆内存: " + MonoHeapSize + "MB", bb); GUI.Label(new Rect(0, fontsize*5, 100, 40), "已占用Mono堆内存:" + MonoUsedSize + "MB", bb); } }
转载请注明原文地址: https://www.6miu.com/read-1250072.html

最新回复(0)