-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
54 lines (49 loc) · 1.77 KB
/
Utils.cs
File metadata and controls
54 lines (49 loc) · 1.77 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//used for drawing our marquee
public static class Utils
{
static Texture2D _whiteTexture;
public static Texture2D WhiteTexture
{
get
{
if (_whiteTexture == null)
{
_whiteTexture = new Texture2D(1, 1);
_whiteTexture.SetPixel(0, 0, Color.white);
_whiteTexture.Apply();
}
return _whiteTexture;
}
}
public static void DrawScreenRect(Rect rect, Color color)
{
GUI.color = color;
GUI.DrawTexture(rect, WhiteTexture);
GUI.color = Color.white;
}
public static void DrawScreenRectBorder(Rect rect, float thickness, Color color)
{
// Top
Utils.DrawScreenRect(new Rect(rect.xMin, rect.yMin, rect.width, thickness), color);
// Left
Utils.DrawScreenRect(new Rect(rect.xMin, rect.yMin, thickness, rect.height), color);
// Right
Utils.DrawScreenRect(new Rect(rect.xMax - thickness, rect.yMin, thickness, rect.height), color);
// Bottom
Utils.DrawScreenRect(new Rect(rect.xMin, rect.yMax - thickness, rect.width, thickness), color);
}
public static Rect GetScreenRect(Vector3 screenPosition1, Vector3 screenPosition2)
{
// Move origin from bottom left to top left
screenPosition1.y = Screen.height - screenPosition1.y;
screenPosition2.y = Screen.height - screenPosition2.y;
// Calculate corners
var topLeft = Vector3.Min(screenPosition1, screenPosition2);
var bottomRight = Vector3.Max(screenPosition1, screenPosition2);
// Create Rect
return Rect.MinMaxRect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y);
}
}