Skip to content

Instantly share code, notes, and snippets.

@NPatch
Last active March 24, 2022 00:54

Revisions

  1. NPatch revised this gist Mar 24, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions mem_profiler_texture_info_extension.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    Cut/Move the com.unity.memprofiler folder from <ProjectFolder>/Library/PackageCache to <ProjectFolder>/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:
  2. NPatch revised this gist Mar 24, 2022. 1 changed file with 6 additions and 7 deletions.
    13 changes: 6 additions & 7 deletions mem_profiler_texture_info_extension.md
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,14 @@
    Under com.unity.memprofiler.../Editor/UI, edit SelectedItemDetailsForTypesAndObjects.cs
    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)"
    near line 200, add:

    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("Texture") ||
    selectedUnityObject.NativeTypeName.Contains("Texture"))
    if(selectedUnityObject.ManagedTypeName.Contains("Texture2D"))
    {
    EditorAssetFinderUtility.Findings findings = EditorAssetFinderUtility.FindObject(snapshot, selectedUnityObject);
    if(findings.FailReason == EditorAssetFinderUtility.SearchFailReason.Found && (findings.FoundObject is Texture2D))
    @@ -18,8 +17,8 @@ if(selectedUnityObject.ManagedTypeName.Contains("Texture") ||
    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 if(findings.FailReason == EditorAssetFinderUtility.SearchFailReason.NotFound && selectedUnityObject.IsRuntimeCreated)
    {//RenderTextures
    else
    {//do sth on error
    }
    }
    ```
  3. NPatch created this gist Mar 24, 2022.
    25 changes: 25 additions & 0 deletions mem_profiler_texture_info_extension.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    Under 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)"
    near line 200, add:
    ```
    if(selectedUnityObject.ManagedTypeName.Contains("Texture") ||
    selectedUnityObject.NativeTypeName.Contains("Texture"))
    {
    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 if(findings.FailReason == EditorAssetFinderUtility.SearchFailReason.NotFound && selectedUnityObject.IsRuntimeCreated)
    {//RenderTextures
    }
    }
    ```