using System;
using SRF;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.UI;
namespace SRDebugger.UI.Controls.Profiler
{
public class ProfilerMonoBlock : SRMonoBehaviourEx
{
private float _lastRefresh;
[RequiredField]
public Text CurrentUsedText;
[RequiredField]
public GameObject NotSupportedMessage;
[RequiredField]
public Slider Slider;
[RequiredField]
public Text TotalAllocatedText;
protected override void OnEnable()
{
base.OnEnable();
NotSupportedMessage.SetActive(!UnityEngine.Profiling.Profiler.supported);
CurrentUsedText.gameObject.SetActive(UnityEngine.Profiling.Profiler.supported);
TriggerRefresh();
}
protected override void Update()
{
base.Update();
if (SRDebug.Instance.IsDebugPanelVisible && Time.realtimeSinceStartup - _lastRefresh > 1f)
{
TriggerRefresh();
_lastRefresh = Time.realtimeSinceStartup;
}
}
public void TriggerRefresh()
{
long num = ((!UnityEngine.Profiling.Profiler.supported) ? GC.GetTotalMemory(false) : UnityEngine.Profiling.Profiler.GetMonoHeapSize());
uint monoUsedSize = UnityEngine.Profiling.Profiler.GetMonoUsedSize();
Slider.maxValue = num;
Slider.value = monoUsedSize;
long num2 = num >> 10;
num2 /= 1024;
uint num3 = monoUsedSize >> 10;
num3 /= 1024;
TotalAllocatedText.text = "Total: {0}MB".Fmt(num2);
if (num3 != 0)
{
CurrentUsedText.text = "{0}MB".Fmt(num3);
}
}
public void TriggerCollection()
{
GC.Collect();
TriggerRefresh();
}
}
}