You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
740 B
30 lines
740 B
using UnityEngine;
|
|
|
|
namespace uc
|
|
{
|
|
public static class RectExtensions
|
|
{
|
|
public static Rect FitIntoRect(this Rect rect, Rect target)
|
|
{
|
|
float srcAspect = rect.width/ rect.height;
|
|
float dstAspect = target.width / target.height;
|
|
|
|
Rect rr = target;
|
|
if (srcAspect > dstAspect)
|
|
{
|
|
float h = rr.height;
|
|
rr.height = rr.width / srcAspect;
|
|
rr.y += h * 0.5f - rr.height * 0.5f;
|
|
}
|
|
else
|
|
{
|
|
float w = rr.width;
|
|
rr.width = rr.height * srcAspect;
|
|
rr.x += w * 0.5f - rr.width * 0.5f;
|
|
}
|
|
|
|
return rr;
|
|
}
|
|
}
|
|
|
|
}
|
|
|