FPSDisplayer

Unity3D 2017. 5. 17. 18:34
반응형





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using UnityEngine;
using UnityEditor;
using System.Collections;
 
public class FPSDisplayer : MonoBehaviour
{
#if USE_DEBUG
    private float deltaTime = 0.0f;
    private GUIStyle style;
    private int width;
    private int height;
    private long totalReservedMemory;
    private long totalAllocMemory;
    private long totalUnusedReservedMemory;
 
    void Awake()
    {
        this.width = Screen.width;
        this.height = Screen.height;
        this.style = new GUIStyle();
        Font font = Resources.GetBuiltinResource<Font>("Arial.ttf");
        this.style.font = font;
        //UnityEngine.Profiling.Profiler.logFile = "mylog.log";
        //UnityEngine.Profiling.Profiler.enabled = true;
    }
    void Update()
    {
        this.deltaTime += (Time.deltaTime - this.deltaTime) * 0.1f;
 
        this.totalReservedMemory = UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong();
        this.totalAllocMemory = UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong();
        this.totalUnusedReservedMemory = UnityEngine.Profiling.Profiler.GetTotalUnusedReservedMemoryLong();
    }
 
    private void ShowFPS()
    {
        Rect rect = new Rect(00this.width, this.height * / 100);
        this.style.alignment = TextAnchor.UpperLeft;
        this.style.fontSize = this.height * / 100;
        this.style.normal.textColor = Color.yellow;
        float msec = this.deltaTime * 1000.0f;
        float fps = 1.0f / this.deltaTime;
        string text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps);
        GUI.Label(rect, text, this.style);
    }
 
    private void ShowReservedMemory()
    {
        Rect rect = new Rect(020this.width, this.height * / 100);
        this.style.alignment = TextAnchor.UpperLeft;
        this.style.fontSize = this.height * / 100;
        this.style.normal.textColor = Color.yellow;
        string text = string.Format("사용가능한 메모리: {0}MB"this.ConvertBytesToMegabytes(this.totalReservedMemory).ToString("N"));
        GUI.Label(rect, text, this.style);
    }
 
    private void ShowAllocMemory()
    {
        Rect rect = new Rect(040this.width, this.height * / 100);
        this.style.alignment = TextAnchor.UpperLeft;
        this.style.fontSize = this.height * / 100;
        this.style.normal.textColor = Color.yellow;
        string text = string.Format("사용하고있음: {0}MB"this.ConvertBytesToMegabytes(this.totalAllocMemory).ToString("N"));
        GUI.Label(rect, text, this.style);
    }
 
    private void ShowUnusedReservedMemory()
    {
        Rect rect = new Rect(060this.width, this.height * / 100);
        this.style.alignment = TextAnchor.UpperLeft;
        this.style.fontSize = this.height * / 100;
        this.style.normal.textColor = Color.yellow;
        string text = string.Format("남은량: {0}MB"this.ConvertBytesToMegabytes(this.totalUnusedReservedMemory).ToString("N"));
        GUI.Label(rect, text, this.style);
    }
 
    void OnGUI()
    {
        
        this.ShowFPS();
 
        this.ShowReservedMemory();
 
        this.ShowAllocMemory();
 
        this.ShowUnusedReservedMemory();
 
    }
 
    private double ConvertBytesToMegabytes(long bytes)
    {
        return (bytes / 1024f) / 1024f;
    }
 
#endif
}
cs


반응형

'Unity3D' 카테고리의 다른 글

결제 크랙 막기  (0) 2017.05.19
Android In-App Billing 보안 완벽 정리  (0) 2017.05.19
IL2CPP 최적화  (0) 2017.05.12
[C#]enum의 Flag 연산!  (0) 2017.04.28
Unity 5 마지막 버전 Unity 5.6 안내  (0) 2017.04.20
: