-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathUIViewport.cs
45 lines (38 loc) · 1.01 KB
/
UIViewport.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
45
using UnityEngine;
[AddComponentMenu("NGUI/UI/Viewport Camera")]
[ExecuteInEditMode]
[RequireComponent(typeof(Camera))]
public class UIViewport : MonoBehaviour
{
public Camera sourceCamera;
public Transform topLeft;
public Transform bottomRight;
public float fullSize = 1f;
private Camera mCam;
private void Start()
{
mCam = GetComponent<Camera>();
if (sourceCamera == null)
{
sourceCamera = Camera.main;
}
}
private void LateUpdate()
{
if (topLeft != null && bottomRight != null)
{
Vector3 vector = sourceCamera.WorldToScreenPoint(topLeft.position);
Vector3 vector2 = sourceCamera.WorldToScreenPoint(bottomRight.position);
Rect rect = new Rect(vector.x / (float)Screen.width, vector2.y / (float)Screen.height, (vector2.x - vector.x) / (float)Screen.width, (vector.y - vector2.y) / (float)Screen.height);
float num = fullSize * rect.height;
if (rect != mCam.rect)
{
mCam.rect = rect;
}
if (mCam.orthographicSize != num)
{
mCam.orthographicSize = num;
}
}
}
}