| | 1 | | // Copyright (c) 2020-2024 dotBunny Inc. |
| | 2 | | // dotBunny licenses this file to you under the BSL-1.0 license. |
| | 3 | | // See the LICENSE file in the project root for more information. |
| | 4 | |
|
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace GDX |
| | 8 | | { |
| | 9 | | public static class RectExtensions |
| | 10 | | { |
| | 11 | | public static Rect GetCenteredRect(this Rect parentWindowPosition, Vector2 size, float safeZone = 0.9f) |
| 0 | 12 | | { |
| 0 | 13 | | Rect centeredWindowPosition = new Rect |
| | 14 | | { |
| | 15 | | x = 0.0f, |
| | 16 | | y = 0.0f, |
| | 17 | | width = Mathf.Min(size.x, parentWindowPosition.width * safeZone), |
| | 18 | | height = Mathf.Min(size.y, parentWindowPosition.height * safeZone) |
| | 19 | | }; |
| 0 | 20 | | float num1 = (float)((parentWindowPosition.width - (double)centeredWindowPosition.width) * 0.5); |
| 0 | 21 | | float num2 = (float)((parentWindowPosition.height - (double)centeredWindowPosition.height) * 0.5); |
| 0 | 22 | | centeredWindowPosition.x = parentWindowPosition.x + num1; |
| 0 | 23 | | centeredWindowPosition.y = parentWindowPosition.y + num2; |
| 0 | 24 | | return centeredWindowPosition; |
| 0 | 25 | | } |
| | 26 | | } |
| | 27 | | } |