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; } } }