Skip to content

Instantly share code, notes, and snippets.

@NPatch
Last active March 24, 2022 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NPatch/6ccd149e299b18bf9637283ae4271f49 to your computer and use it in GitHub Desktop.
Save NPatch/6ccd149e299b18bf9637283ae4271f49 to your computer and use it in GitHub Desktop.
MemoryProfiler texture info

Cut/Move the com.unity.memprofiler folder from /Library/PackageCache to /Packages and remove the com.unity.memprofiler entry from the manifest in the same folder. This prevents PackageManager to reset any changes you make and lets you edit the code normally.

Under Packages/com.unity.memprofiler.../Editor/UI, edit SelectedItemDetailsForTypesAndObjects.cs

Add the following usings:

using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;

and further down at the end of the "internal void HandleUnityObjectDetails(CachedSnapshot snapshot, MemorySampleSelection memorySampleSelection, UnifiedUnityObjectInfo selectedUnityObject)" function near line 200, add:

if(selectedUnityObject.ManagedTypeName.Contains("Texture2D"))
{
  EditorAssetFinderUtility.Findings findings = EditorAssetFinderUtility.FindObject(snapshot, selectedUnityObject);
  if(findings.FailReason == EditorAssetFinderUtility.SearchFailReason.Found && (findings.FoundObject is Texture2D))
  {
    Texture t = findings.PreviewImage;
    string s = string.Format("Format: {0}, IsCompressed: {1}, RuntimeCreated: {2}", t.graphicsFormat.ToString(), GraphicsFormatUtility.IsCompressedFormat(t.graphicsFormat), selectedUnityObject.IsRuntimeCreated);
    m_UI.AddDynamicElement("Texture Format", s);
  }
  else
  {//do sth on error
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment