Var textSize = style.CalcSize(new GUIContent(text)) įloat textWidthWorld = GetHorizontalScreenToWorldSize(camera, textSize.x) Private static float GetTextWidthWorld(string text, GUIStyle style, Camera camera)
![unity 2d tile map editor unity 2d tile map editor](https://www.filterforge.com/filters/631-normal.jpg)
Var handlePos = grid.CellToWorld(new Vector3Int(x, y, 0)) Private static void DrawInCells(Grid grid, IEnumerable xCells, IEnumerable 圜ells, float textHeight) Handles.Label(handlePos, text, labelStyle) įloat 圜enter = grid.GetCellCenterWorld(new Vector3Int(0, y, 0)).y įloat xText = bottomLeftWorld.x + offset įloat yText = 圜enter + textHalfHeightWorld Var handlePos = new Vector3(xText, yText, 0) Vector3 bottomLeftWorld, float offset, IEnumerable 圜ells, float textHalfHeightWorld)įloat textHalfWidthWorld = GetTextWidthWorld(text, labelStyle, camera) * 0.5f įloat xCenter = grid.GetCellCenterWorld(new Vector3Int(x, 0, 0)).x įloat xText = xCenter - textHalfWidthWorld įloat yText = bottomLeftWorld.y + offset Private static void DrawInAxis(Grid grid, IEnumerable xCells, GUIStyle labelStyle, Camera camera, If (GetTextWidthWorld(cellText,, camera) > * 0.7f)ĭrawInAxis(grid, xCellsList, labelStyle, camera, bottomLeftWorld, offset, 圜ellsList, textHalfHeightWorld) ĭrawInCells(grid, xCellsList, 圜ellsList, textHeightWorld) YCells = Enumerable.Range(minCellY, maxCellY - minCellY + 1) YCells = MathUtils.SplitNicely(minCellY, maxCellY).Select(y => (int) y) Int maxCellY = grid.WorldToCell(topRightWorld).y Int minCellY = grid.WorldToCell(bottomLeftWorld).y XCells = Enumerable.Range(minCellX, maxCellX - minCellX + 1) XCells = MathUtils.SplitNicely(minCellX, maxCellX).Select(x => (int) x) Int maxCellX = grid.WorldToCell(topRightWorld).x įloat minCellXTextSize = GetTextWidthWorld($"", labelStyle, camera) įloat maxWidthSize = Mathf.Max(minCellXTextSize, maxCellXTextSize) Int minCellX = grid.WorldToCell(bottomLeftWorld).x Var tmpTextSize = labelStyle.CalcSize(new GUIContent("0")) įloat textHeightWorld = GetVerticalScreenToWorldSize(camera, tmpTextSize.y) įloat textHalfHeightWorld = textHeightWorld * 0.5f Var topRightWorld = camera.ViewportToWorldPoint(Vector3.one) Var bottomLeftWorld = camera.ViewportToWorldPoint(Vector3.zero) Private static void Draw(SceneView sceneView, Grid grid) Public static void DrawGizmo(Tilemap tilemap, GizmoType gizmoType)ĭraw(SceneView.currentDrawingSceneView, tilemap.layoutGrid) Public static void DrawGizmo(Grid grid, GizmoType gizmoType)ĭraw(SceneView.currentDrawingSceneView, grid)
![unity 2d tile map editor unity 2d tile map editor](https://cdn-ak.f.st-hatena.com/images/fotolife/a/assetsale/20160325/20160325232745.jpg)
When zoomed in enough it draws the coordinates inside each tile, instead of axes, to ease visualization. More info in this tweet.īasically, what it does is draw the axes' cordinates of a selected Grid or Tilemap component. Var c3 = new Vector3(, ) + tp ĭebug.DrawLine(new Vector3(tp.x, + tp.y), new Vector3(tp.x, + tp.y), een) ĭebug.DrawLine(new Vector3( + tp.x, tp.y), new Vector3( + tp.x, tp.y), een) Public class DrawTilemapBorder : MonoBehaviour
#UNITY 2D TILE MAP EDITOR CODE#
I might extend this and put it to my GitHub, but here is the current version.Īdd the script to any Tilemap for which you want to show bounds + origin, and the code will run in Editor automatically. It is also possible to see the unused space where user has erased the tiles, but hasn't compressed the bounds: Script does take into account position of Tilemap in World space, but if the Grid or Tilemap is scaled or rotated the rendering no longer will be aligned to Tilemap. Red border shows the Tilemap current bounds, green cross shows the 0,0,0 position of Tilemap. It is an old question - There doesn't still seem to be easy way to show clearly the origin and the bounds of a Tilemap, but it can be solved with a script that runs in the Editor like Philipp said.