Forums › 💬 NodeCanvas › 🗨️ General Discussion › GraphEditor.DrawGrid fix performance › Reply To: GraphEditor.DrawGrid fix performance
Oh :(. So try something like that:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
private static MethodInfo s_beginLineDrawingMethod; public static bool BeginLineDrawing(Matrix4x4 _matrix, bool _dottedLines, int _mode) { if(s_beginLineDrawingMethod == null) s_beginLineDrawingMethod = typeof(Handles).GetMethod("BeginLineDrawing", BindingFlags.NonPublic | BindingFlags.Static); return (bool)s_beginLineDrawingMethod.Invoke(null, new object[] {_matrix, _dottedLines, _mode}); } private static MethodInfo s_endLineDrawinggMethod; public static void EndLineDrawing() { if(s_endLineDrawinggMethod == null) s_endLineDrawinggMethod = typeof(Handles).GetMethod("EndLineDrawing", BindingFlags.NonPublic | BindingFlags.Static); s_endLineDrawinggMethod.Invoke(null, null); } //Draw a simple grid void DrawGrid(Rect container, Vector2 offset, float zoomFactor) { if (Event.current.type != EventType.Repaint) return; var scaledX = (container.width - offset.x) / zoomFactor; var scaledY = (container.height - offset.y) / zoomFactor; BeginLineDrawing(Handles.matrix, false,1); for (var i = 0 - (int)offset.x; i < scaledX; i++) { if (i % gridSize == 0) { GL.Color(new Color(0, 0, 0, i % (gridSize * 5) == 0 ? 0.2f : 0.1f)); GL.Vertex(new Vector3(i, 0, 0)); GL.Vertex(new Vector3(i, scaledY, 0)); } } for (var i = 0 - (int)offset.y; i < scaledY; i++) { if (i % gridSize == 0) { GL.Color(new Color(0, 0, 0, i % (gridSize * 5) == 0 ? 0.2f : 0.1f)); GL.Vertex(new Vector3(0, i, 0)); GL.Vertex(new Vector3(scaledX, i, 0)); } } EndLineDrawing(); } |
It should works!
