How to get the selected scene's triangles in code in menuitem?
How to get the selected scene's triangles in code in menuitem?
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:
Scene 1: +/-4 800 tris
Scene 2: +/-1 700 k
Drag both scenes in, now you see the Triangle count is wrong. This is because of extra camera.
Delete camera to get right count.
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.
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.
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