Skip to content

Instantly share code, notes, and snippets.

@sunny352
Created August 12, 2015 02:30
Show Gist options
  • Save sunny352/bee8b382f339cc9a80f9 to your computer and use it in GitHub Desktop.
Save sunny352/bee8b382f339cc9a80f9 to your computer and use it in GitHub Desktop.
游戏帧率及内存占用统计显示工具
using UnityEngine;
using System.Collections;
public class ShowProfile : MonoBehaviour
{
public float SampleTime = 0.5f;
private float m_lastUpdateTime = 0.0f;
private float m_fps = 0.0f;
private int m_frame = 0;
void Update()
{
++m_frame;
}
void FixedUpdate()
{
float currentTime = Time.realtimeSinceStartup;
float flameTime = currentTime - m_lastUpdateTime;
if (flameTime >= SampleTime)
{
m_fps = m_frame / flameTime;
m_lastUpdateTime = currentTime;
m_frame = 0;
long monoMemory = System.GC.GetTotalMemory(false);
uint totalMemory = Profiler.GetTotalAllocatedMemory();
m_info = string.Format("Total:{0:0.0}MB\nMono:{1:0.0}MB\nFPS:{2:0.0}", totalMemory / 1024.0f / 1024.0f, monoMemory / 1024.0f / 1024.0f, m_fps);
}
}
private Rect m_place = new Rect(0.0f, 0.0f, 300, 100);
private string m_info = string.Empty;
void OnGUI()
{
GUI.Label(m_place, m_info);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment