perf: Optimize performance for status view
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Text;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -11,17 +12,30 @@ namespace Cryville.EEW.Unity.UI {
|
|||||||
_textView = GetComponent<TMP_Text>();
|
_textView = GetComponent<TMP_Text>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringBuilder _sb = new();
|
||||||
|
char[] _buffer = new char[256];
|
||||||
void Update() {
|
void Update() {
|
||||||
_textView.text = string.Format(
|
_sb.Clear();
|
||||||
|
_sb.AppendFormat(
|
||||||
CultureInfo.InvariantCulture,
|
CultureInfo.InvariantCulture,
|
||||||
"FPS: i{0:0} / s{1:0}\nSMem: {2:N0} / {3:N0}\nIMem: {4:N0} / {5:N0}",
|
"FPS: i{0:0} / s{1:0}\n",
|
||||||
1 / Time.deltaTime,
|
1 / Time.deltaTime,
|
||||||
1 / Time.smoothDeltaTime,
|
1 / Time.smoothDeltaTime
|
||||||
|
);
|
||||||
|
_sb.AppendFormat(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"SMem: {0:N0} / {1:N0}\n",
|
||||||
UnityEngine.Profiling.Profiler.GetMonoUsedSizeLong(),
|
UnityEngine.Profiling.Profiler.GetMonoUsedSizeLong(),
|
||||||
UnityEngine.Profiling.Profiler.GetMonoHeapSizeLong(),
|
UnityEngine.Profiling.Profiler.GetMonoHeapSizeLong()
|
||||||
|
);
|
||||||
|
_sb.AppendFormat(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"IMem: {0:N0} / {1:N0}",
|
||||||
UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong(),
|
UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong(),
|
||||||
UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong()
|
UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong()
|
||||||
);
|
);
|
||||||
|
_sb.CopyTo(0, _buffer, _sb.Length);
|
||||||
|
_textView.SetText(_buffer, 0, _sb.Length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user