Memory.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEngine.Profiling;
  4. namespace EnhancedHierarchy.Icons {
  5. public sealed class Memory : IconBase {
  6. private float m_width = 0f;
  7. private static readonly GUIContent label = new GUIContent();
  8. public override string Name { get { return "Memory Used"; } }
  9. public override float Width { get { return m_width + 4f; } }
  10. private GUIStyle Style { get { return Styles.applyPrefabStyle; } }
  11. public override void Init() {
  12. m_width = 0f;
  13. if (!EnhancedHierarchy.IsGameObject)
  14. return;
  15. if (Preferences.Tooltips && !Preferences.RelevantTooltipsOnly)
  16. label.tooltip = "Used Memory";
  17. else
  18. label.tooltip = string.Empty;
  19. #if UNITY_5_6_OR_NEWER
  20. var memory = Profiler.GetRuntimeMemorySizeLong(EnhancedHierarchy.CurrentGameObject);
  21. #else
  22. var memory = Profiler.GetRuntimeMemorySize(EnhancedHierarchy.CurrentGameObject);
  23. #endif
  24. if (memory == 0)
  25. return;
  26. label.text = EditorUtility.FormatBytes(memory);
  27. m_width = Style.CalcSize(label).x;
  28. }
  29. public override void DoGUI(Rect rect) {
  30. if (m_width <= 0f)
  31. return;
  32. rect.xMin += 2f;
  33. rect.xMax -= 2f;
  34. using(new GUIColor(Styles.backgroundColorEnabled))
  35. EditorGUI.LabelField(rect, label, Style);
  36. }
  37. }
  38. }