Answer the question
In order to leave comments, you need to log in
Why does the editor window start to slow down because of DrawGizmo?
Hello dear experts.
I'm writing a custom tile drawer. I have the following code for drawing a grid in the editor screen by tile size:
[CustomEditor(typeof(GameObject))]
public class SceneGUITest : Editor
{
[DrawGizmo(GizmoType.NotInSelectionHierarchy)]
static void RenderCustomGizmo(Transform objectTransform, GizmoType gizmoType)
{
if (isEnabled && isGrid)
{
Gizmos.color = Color.white;
Vector3 minGrid = SceneView.currentDrawingSceneView.camera.ScreenPointToRay(new Vector2(0f, 0f)).origin;
Vector3 maxGrid = SceneView.currentDrawingSceneView.camera.ScreenPointToRay(new Vector2(SceneView.currentDrawingSceneView.camera.pixelWidth, SceneView.currentDrawingSceneView.camera.pixelHeight)).origin;
for (float i = Mathf.Round(minGrid.x / gridSize.x) * gridSize.x; i < Mathf.Round(maxGrid.x / gridSize.x) * gridSize.x && gridSize.x > 0.05f; i+=gridSize.x)
Gizmos.DrawLine(new Vector3(i,minGrid.y,0.0f), new Vector3(i,maxGrid.y,0.0f));
for (float j = Mathf.Round(minGrid.y / gridSize.y) * gridSize.y; j < Mathf.Round(maxGrid.y / gridSize.y) * gridSize.y && gridSize.y > 0.05f; j+=gridSize.y)
Gizmos.DrawLine(new Vector3(minGrid.x,j,0.0f), new Vector3(maxGrid.x,j,0.0f));
SceneView.RepaintAll();
}
}
Answer the question
In order to leave comments, you need to log in
It's very simple:
The method with the attribute "[DrawGizmo(GizmoType.NotInSelectionHierarchy)]" is called for each unselected object in the scene. The more objects, the more often it is called, which is the reason for the brakes.
PS So far I have not found an elegant way to get a single method call. But as an option, you can create an object with the HideFlags.HideAndDontSave flag and draw through it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question