How to get the selected scene's triangles in code in menuitem?

Started by
5 comments, last by PlayerA 5 years, 9 months ago

How to get the selected scene's triangles in code in menuitem?712151901__20180717152213.png.b42a277159557880784469997f536c13.png1749387170__20180717152228.png.3e7feed26f5ebb21adf754207293eaf7.png

Advertisement

Get this data.Any one can teach me?QAQ

微信截图11.png

The purpose is to get all scenes'tris for performance optimization

This is available through UnityEditor.UnityStats.triangles.  However, it's available only in the editor I think, not in a build.

7 hours ago, PlayerA said:

The purpose is to get all scenes'tris for performance optimization

You only need 1 scene info at a time. Triangles are counted by scene.

You can also load all scenes at the same time, to see all stats:

SceneOne.jpg.5bca8a87bafc869c12ac97280d6a474c.jpg

Scene 1: +/-4 800 tris

SceneTwo.jpg.e25f86d7e4c0055d6ed0b8b9843b9a40.jpg

Scene 2: +/-1 700 k

SceneMerge.jpg.39f312c6a3cc5d9221acececc0e257c3.jpg

Drag both scenes in, now you see the Triangle count is wrong. This is because of extra camera.

Delete camera to get right count.

SceneMergeCorrect.jpg.97e58348208fd361a95c07ffbeb7f096.jpg

Scene 1 + Scene 2 -> +/- (4 800 + 1 700 k) = +/- 7 200 triangles. Extra triangles is from shadows.

Note: Removing 100 - 1000 triangles doesn't matter. You need to remove at least 24 000 to get better performance. That is why Unity doesn't tell you about every triangle.

Thank you for your answer!Now I found a way of doing it:

Scene scene = EditorSceneManager.OpenScene(path, OpenSceneMode.Single);

MeshFilter mf = root.GetComponent<MeshFilter>();

mf.sharedMesh.triangles.Length/3;

But the result is not the same as the tris in the Game window.

imageproxy.php?img=&key=2aa9ad0c79a985be222.png.a0781ec4537c10b3b9331de682082c19.png

333.png.b52392ea86dc1ed7d32c4258c3a83a33.png

I found one reason

On 7/18/2018 at 1:47 AM, Scouting Ninja said:

Extra triangles is from shadows.

Thank you for your reminding,the main extra triangles is from shadows.444.png.c01e328abcaa9f9bab316501b10d9d4e.png555.png.e59128467acaf0c0bba1e1f0a82607cc.png
But the new problem appears:

How can I get the shadows' tris...

Note:
This method is a bit troublesome because it take a lot of time to open every scene..But at least this can solve the problem.I wonder if I can get data directly without opening the scene, because the data is static, and it is there.Anyone has any idea can share here...Thank you again for your help

This topic is closed to new replies.

Advertisement