-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenArray.cs
More file actions
71 lines (54 loc) · 2.03 KB
/
ScreenArray.cs
File metadata and controls
71 lines (54 loc) · 2.03 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Get a Screen Array and illustrate with spheres on an Orthographic camera
// From TopLeft to BottomRight corner with borders
private Camera cam;
public float borderLimit;
[SerializeField] private Vector3 center;
[SerializeField] private Vector3 topleft;
[SerializeField] private Vector3 topRight;
[SerializeField] private Vector3 bottomLeft;
[SerializeField] private Vector3 bottomRight;
[SerializeField] private float pixelX;
[SerializeField] private float pixelY;
private void Awake()
{
cam = Camera.main;
}
private void Start()
{
SetPosition(center);
DrawArrayOnCanvas();
}
// Ortho Screen Camera Boundaries - Center, TopLeft, TopRight, BottomLeft, BottomRight
private void Ortho_ScreenCameraBoundaries()
{
// Get pixel width and height
pixelX = cam.pixelWidth;
pixelY = cam.pixelHeight;
// Set Screen Coordinates Boundaries
center = cam.ScreenToWorldPoint(new Vector3(pixelX / 2, pixelY / 2, 0));
float x1 = borderLimit;
float x2 = pixelX - borderLimit;
float y1 = pixelY - borderLimit;
float y2 = borderLimit;
topleft = cam.ScreenToWorldPoint(new Vector3(x1, y1, 0));
topRight = cam.ScreenToWorldPoint(new Vector3(x2, y1, 0));
bottomLeft = cam.ScreenToWorldPoint(new Vector3(x1, y2, 0));
bottomRight = cam.ScreenToWorldPoint(new Vector3(x2, y2, 0));
}
// Ex : Position gameoject at the center of the screen
private void SetPosition (Vector3 position)
{
transform.position = topleft;
}
// Draw an array of Spheres (TopLeft to BottomRight)
private void DrawArrayOnCanvas()
{
for (var y = bottomLeft.y; y <= topRight.y; y++)
{
for (var x = bottomLeft.x; x <= topRight.x; x++)
{
GameObject dot = GameObject.CreatePrimitive(PrimitiveType.Sphere);
dot.transform.position = new Vector2(x, y);
}
}
}