using UnityEngine; using System.Collections; public static class AdvancedGizmo { public enum CircleCloseType{ None, Direct, ToCenter } public static void Circle(float radius, float angle = 360.0f, int tesselation = 12, CircleCloseType close = CircleCloseType.None, Matrix4x4? transform = null){ var matrixBackup = Gizmos.matrix; Gizmos.matrix = transform.HasValue ? transform.Value : Matrix4x4.identity; for (int i = 0; i < tesselation; ++i) { float angle0 = i * (angle * Mathf.Deg2Rad / tesselation); float angle1 = (i + 1) * (angle * Mathf.Deg2Rad / tesselation); var p0 = new Vector3(Mathf.Sin(angle0) * radius, 0, Mathf.Cos(angle0) * radius); var p1 = new Vector3(Mathf.Sin(angle1) * radius, 0, Mathf.Cos(angle1) * radius); Gizmos.DrawLine(p0, p1); } if (close != CircleCloseType.None) { float angle1 = angle * Mathf.Deg2Rad; var p0 = new Vector3(Mathf.Sin(0) * radius, 0, Mathf.Cos(0) * radius); var p1 = new Vector3(Mathf.Sin(angle1) * radius, 0, Mathf.Cos(angle1) * radius); if(close == CircleCloseType.Direct){ Gizmos.DrawLine(p0, p1); }else{ Gizmos.DrawLine(p0, Vector3.zero); Gizmos.DrawLine(p1, Vector3.zero); } } Gizmos.matrix = matrixBackup; } public static void CircleArrow(float radius, float angle = 360.0f, int tesselation = 12, CircleCloseType close = CircleCloseType.None, Matrix4x4? transform = null){ Circle(radius, angle, tesselation, close, transform); float len = 0.03f; float wid = 0.01f; float angleOffset = 2.0f * Mathf.Asin (len / (2.0f * radius)) * Mathf.Sign(angle); var matrixBackup = Gizmos.matrix; Gizmos.matrix = transform.HasValue ? transform.Value : Matrix4x4.identity; var radiusVector = new Vector3(Mathf.Sin(0), 0, Mathf.Cos(0)); var p1 = new Vector3(Mathf.Sin(angleOffset), 0, Mathf.Cos(angleOffset)) * radius; var p0 = radiusVector * radius; var dir = (p1 - p0).normalized; var dir2 = Vector3.Cross (dir, Vector3.up).normalized; Gizmos.DrawLine(p0, p1 + dir2 * wid); Gizmos.DrawLine(p0, p1 - dir2 * wid); Gizmos.DrawLine(p1 + dir2 * wid, p1 - dir2 * wid); Gizmos.matrix = matrixBackup; } }