using UnityEngine; public class Helpers { public static void DrawPlane(Vector3 position, Vector3 normal) { Vector3 v3; if (normal.normalized != Vector3.forward) v3 = Vector3.Cross(normal, Vector3.forward).normalized * normal.magnitude; else v3 = Vector3.Cross(normal, Vector3.up).normalized * normal.magnitude; ; var corner0 = position + v3; var corner2 = position - v3; var q = Quaternion.AngleAxis(90.0f, normal); v3 = q * v3; var corner1 = position + v3; var corner3 = position - v3; Debug.DrawLine(corner0, corner2, Color.green); Debug.DrawLine(corner1, corner3, Color.green); Debug.DrawLine(corner0, corner1, Color.green); Debug.DrawLine(corner1, corner2, Color.green); Debug.DrawLine(corner2, corner3, Color.green); Debug.DrawLine(corner3, corner0, Color.green); Debug.DrawRay(position, normal, Color.red); } public static void DrawLine(Vector3 p1, Vector3 p2, float width) { int count = 1 + Mathf.CeilToInt(width); // how many lines are needed. if (count == 1) { Gizmos.DrawLine(p1, p2); } else { Camera c = Camera.current; if (c == null) { Debug.LogError("Camera.current is null"); return; } var scp1 = c.WorldToScreenPoint(p1); var scp2 = c.WorldToScreenPoint(p2); Vector3 v1 = (scp2 - scp1).normalized; // line direction Vector3 n = Vector3.Cross(v1, Vector3.forward); // normal vector for (int i = 0; i < count; i++) { Vector3 o = 0.99f * n * width * ((float) i / (count - 1) - 0.5f); Vector3 origin = c.ScreenToWorldPoint(scp1 + o); Vector3 destiny = c.ScreenToWorldPoint(scp2 + o); Gizmos.DrawLine(origin, destiny); } } } public static float GetMinComponent(Vector3 vector) { if (vector.x <= vector.y && vector.x <= vector.z) return vector.x; if (vector.y <= vector.x && vector.y <= vector.z) return vector.y; return vector.z; } public static long RoundToLong(float f) { return (long) Mathf.Round(f); } }