unity运行中抓显示中的贴图数量和内存

private void DetectTexture(out long textureMemory,out int textureNum)
    {
        textureMemory = 0;
        textureNum = 0;
        var textures = Resources.FindObjectsOfTypeAll(typeof(Texture));
        foreach (Texture t in textures)
        {

            if (t.hideFlags != HideFlags.None )
                continue;

            textureNum++;

            long memoryUsed = Profiler.GetRuntimeMemorySizeLong(t);

            Debug.Log("Texture: " + t.name + ": Memory: " + (memoryUsed / 1000000f));

            textureMemory += memoryUsed;
        }

        //Debug.LogError("texture num:"+tnum  +" memory:"+ totalTextureMemorySize);

        //return totalTextureMemorySize;

    }

 抓出的数据与Profiler/Memory/Assets/Texture/中数据基本吻合

原文地址:https://www.cnblogs.com/nafio/p/12715297.html