12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System;
- using UnityEngine;
- [ExecuteInEditMode]
- [RequireComponent(typeof(Camera))]
- [AddComponentMenu("NGUI/UI/Viewport Camera")]
- public class UIViewport : MonoBehaviour
- {
- private void Start()
- {
- this.mCam = base.GetComponent<Camera>();
- if (this.sourceCamera == null)
- {
- this.sourceCamera = Camera.main;
- }
- }
- private void LateUpdate()
- {
- if (this.topLeft != null && this.bottomRight != null)
- {
- Vector3 vector = this.sourceCamera.WorldToScreenPoint(this.topLeft.position);
- Vector3 vector2 = this.sourceCamera.WorldToScreenPoint(this.bottomRight.position);
- Rect rect = new Rect(vector.x / (float)UICamera.ScreenWidth, vector2.y / (float)UICamera.ScreenHeight, (vector2.x - vector.x) / (float)UICamera.ScreenWidth, (vector.y - vector2.y) / (float)UICamera.ScreenHeight);
- float num = this.fullSize * rect.height;
- if (rect != this.mCam.rect)
- {
- this.mCam.rect = rect;
- }
- if (this.mCam.orthographicSize != num)
- {
- this.mCam.orthographicSize = num;
- }
- }
- }
- public Camera sourceCamera;
- public Transform topLeft;
- public Transform bottomRight;
- public float fullSize = 1f;
- private Camera mCam;
- }
|