Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private float CalculateMenuWidth()
- {
- var menuRect = GameObject.Find("Panel").GetComponent<RectTransform>();
- var worldSpaceCorners = new Vector3[4];
- menuRect.GetWorldCorners(worldSpaceCorners);
- return Mathf.Abs(worldSpaceCorners[2].x - worldSpaceCorners[0].x);
- }
- private void ContainWithin(Rect rect)
- {
- // Make sure camera zoom fits inside level
- if (this.cameraComponent.orthographic)
- {
- var h = rect.height;
- var w = rect.width / this.cameraComponent.aspect;
- var newSize = Mathf.Min(w, h) * 0.5f;
- if (this.cameraComponent.orthographicSize > newSize)
- {
- this.cameraComponent.orthographicSize = newSize;
- this.ZoomMin = (int)this.cameraComponent.orthographicSize;
- }
- }
- // Create padding around the map so the UI buttons don't obscure it for ray casting, viewing, etc.
- var paddingRight = this.CalculateMenuWidth();
- var paddingLeft = 0;
- var paddingTop = 0;
- var paddingBottom = 0;
- this.cameraRect = this.cameraComponent.GetCameraWorldRect();
- var correction = Vector3.zero;
- if (this.cameraRect.xMin < rect.xMin + paddingLeft)
- {
- correction.x -= this.cameraRect.xMin - (rect.xMin + paddingLeft);
- }
- if (this.cameraRect.xMax > rect.xMax - paddingRight)
- {
- correction.x -= this.cameraRect.xMax - (rect.xMax - paddingRight);
- }
- if (this.cameraRect.yMin < rect.yMin + paddingBottom)
- {
- correction.y -= this.cameraRect.yMin - (rect.yMin + paddingBottom);
- }
- if (this.cameraRect.yMax > rect.yMax - paddingTop)
- {
- correction.y -= this.cameraRect.yMax - (rect.yMax - paddingTop);
- }
- this.cameraComponent.transform.position += correction;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement