void MyDrawRectOutLine(Texture2D tex) { float left_bottom_x = center.x - width / 2; float right_top_x = center.x + height / 2; float left_bottom_y = center.y - width / 2; float right_top_y = center.y + height / 2; int min_x = (int)left_bottom_x; int max_x = (int)right_top_x; int min_y = (int)left_bottom_y; int max_y = (int)right_top_y; min_x = MyUtility.Clamp(min_x, 0, tex.width); max_x = MyUtility.Clamp(max_x, 0, tex.width); min_y = MyUtility.Clamp(min_y, 0, tex.height); max_y = MyUtility.Clamp(max_y, 0, tex.height); for (int x = min_x; x <= max_x; x++) { tex.SetPixel(x, max_y, colorOutLine); } for (int y = min_y; y <= max_y; y++) { tex.SetPixel(min_x, y, colorOutLine); tex.SetPixel(max_x, y, colorOutLine); } for (int x = min_x; x <= max_x; x++) { tex.SetPixel(x, min_y, colorOutLine); } }
public static void GetPointToLineNearestDistance(Vector3 a, Vector3 b, Vector3 c, out Vector3 res, out float distance) { var CA = c - a; var AB = (b - a).normalized; var t = Vector3.Dot(CA, AB); t = MyUtility.Clamp(t, 0, (b - a).magnitude); var m = t * AB + a; distance = Vector3.Distance(c, m); res = m; }