using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; public static class Utils { public static Rect ScreenSpaceBounds(Transform t, Mesh m, Camera c) { float xMin = 0, xMax = 0, yMin = 0, yMax = 0; for (int i = 0; i < m.vertexCount; i++) { Vector3 v = c.WorldToViewportPoint(t.TransformPoint(m.vertices[i])); if (i == 0) { xMin = xMax = v.x; yMin = yMax = v.y; } else { if (v.x < xMin) xMin = v.x; if (v.x > xMax) xMax = v.x; if (v.y < yMin) yMin = v.y; if (v.y > yMax) yMax = v.y; } } return new Rect(xMin, yMin, xMax - xMin, yMax - yMin); } }