Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69fe35d

Browse files
Update GameViewGridOverlay.cs - adding spacing support
1 parent acb71e7 commit 69fe35d

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

‎Assets/Scripts/Editor/Tools/GameViewGridOverlay.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// draws grid lines in the game view (useful for seeing the resolution of ui elements in the game view)
2-
// usage: attach to a game object in the scene, set gameobject tag to "EditorOnly" to remove from builds
3-
41
using UnityEngine;
52

63
namespace UnityLibrary.EditorTools
@@ -11,9 +8,15 @@ public class GameViewGridOverlay : MonoBehaviour
118
#if UNITY_EDITOR
129
public bool drawGrid = true;
1310

14-
public int gridSpacingX = 64;
15-
public int gridSpacingY = 64;
11+
[Header("Grid Cell Size (visible area)")]
12+
public int gridSizeX = 64;
13+
public int gridSizeY = 64;
14+
15+
[Header("Spacing Between Cells (invisible gap)")]
16+
public int spacingX = 16;
17+
public int spacingY = 16;
1618

19+
[Header("Start Offsets")]
1720
public int startOffsetX = 0;
1821
public int startOffsetY = 0;
1922

@@ -26,16 +29,22 @@ private void OnGUI()
2629
Color oldColor = GUI.color;
2730
GUI.color = gridColor;
2831

29-
// vertical lines
30-
for (int y = startOffsetY; y < Screen.height; y += gridSpacingY)
31-
{
32-
GUI.DrawTexture(new Rect(0, y, Screen.width, 1), Texture2D.whiteTexture);
33-
}
32+
int cellStrideX = gridSizeX + spacingX;
33+
int cellStrideY = gridSizeY + spacingY;
3434

35-
// horizontal lines
36-
for (int x = startOffsetX; x < Screen.width; x += gridSpacingX)
35+
for (int y = startOffsetY; y + gridSizeY <= Screen.height; y += cellStrideY)
3736
{
38-
GUI.DrawTexture(new Rect(x, 0, 1, Screen.height), Texture2D.whiteTexture);
37+
for (int x = startOffsetX; x + gridSizeX <= Screen.width; x += cellStrideX)
38+
{
39+
// Left line
40+
GUI.DrawTexture(new Rect(x, y, 1, gridSizeY), Texture2D.whiteTexture);
41+
// Right line
42+
GUI.DrawTexture(new Rect(x + gridSizeX - 1, y, 1, gridSizeY), Texture2D.whiteTexture);
43+
// Top line
44+
GUI.DrawTexture(new Rect(x, y, gridSizeX, 1), Texture2D.whiteTexture);
45+
// Bottom line
46+
GUI.DrawTexture(new Rect(x, y + gridSizeY - 1, gridSizeX, 1), Texture2D.whiteTexture);
47+
}
3948
}
4049

4150
GUI.color = oldColor;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /