forked from UnityCommunity/UnityLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameViewGridOverlay.cs
More file actions
57 lines (46 loc) · 1.79 KB
/
Copy pathGameViewGridOverlay.cs
File metadata and controls
57 lines (46 loc) · 1.79 KB
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
52
53
54
55
56
57
using UnityEngine;
namespace UnityLibrary.EditorTools
{
[ExecuteAlways]
public class GameViewGridOverlay : MonoBehaviour
{
#if UNITY_EDITOR
public bool drawGrid = true;
[Header("Grid Cell Size (visible area)")]
public int gridSizeX = 64;
public int gridSizeY = 64;
[Header("Spacing Between Cells (invisible gap)")]
public int spacingX = 16;
public int spacingY = 16;
[Header("Start Offsets")]
public int startOffsetX = 0;
public int startOffsetY = 0;
public Color gridColor = new Color(1f, 1f, 1f, 0.5f);
private void OnGUI()
{
if (!drawGrid || Application.isPlaying) return;
Color oldColor = GUI.color;
GUI.color = gridColor;
int cellStrideX = gridSizeX + spacingX;
int cellStrideY = gridSizeY + spacingY;
// Loop until start of the cell is beyond screen, not end of cell
for (int y = startOffsetY; y < Screen.height; y += cellStrideY)
{
for (int x = startOffsetX; x < Screen.width; x += cellStrideX)
{
// Draw full box even if it goes beyond screen edges
// Left
GUI.DrawTexture(new Rect(x, y, 1, gridSizeY), Texture2D.whiteTexture);
// Right
GUI.DrawTexture(new Rect(x + gridSizeX - 1, y, 1, gridSizeY), Texture2D.whiteTexture);
// Top
GUI.DrawTexture(new Rect(x, y, gridSizeX, 1), Texture2D.whiteTexture);
// Bottom
GUI.DrawTexture(new Rect(x, y + gridSizeY - 1, gridSizeX, 1), Texture2D.whiteTexture);
}
}
GUI.color = oldColor;
}
#endif
}
}