-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtensionMethods_Scr.cs
44 lines (41 loc) · 1.64 KB
/
ExtensionMethods_Scr.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class ExtensionMethods_Scr
{
#region Random Points On Screen
public static Vector3 GetRandomPointFromScreen(this Camera camera, int widthPadding, int heightPadding)
{
int screenWidth = camera.pixelWidth;
int screenHeight = camera.pixelHeight;
return camera.ScreenToWorldPoint(new Vector3(
Random.Range(0 + widthPadding, screenWidth - widthPadding),
Random.Range(0 + heightPadding, screenHeight - heightPadding),
-camera.transform.position.z));
}
public static Vector3 GetRandomPointOnHorizontalLine(this Camera camera, int widthPadding, int lineHeight)
{
int screenWidth = camera.pixelWidth;
int screenHeight = camera.pixelHeight;
return camera.ScreenToWorldPoint(new Vector3(
Random.Range(0 + widthPadding, screenWidth - widthPadding),
lineHeight, -camera.transform.position.z));
}
#endregion
#region Camera Demensions In World
public static float GetHeightInWorld(this Camera camera)
{
return camera.ScreenToViewportPoint(new Vector3(0, camera.pixelHeight, -camera.transform.position.z)).y;
}
#endregion
#region Camera Corners In World
public static Vector3 GetUpperLeftCorner(this Camera camera)
{
return camera.ScreenToViewportPoint(new Vector3(0, camera.pixelHeight, -camera.transform.position.z));
}
public static Vector3 GetBottomLeftCorner(this Camera camera)
{
return camera.ScreenToViewportPoint(new Vector3(0, 0, -camera.transform.position.z));
}
#endregion
}