private void SmoothCornerShape(Action <int, Vector2> doThis) { int index = 0; for (int i = 0; i < Shape.Corners.Length; i++) { // straight Vector2 a = Shape.Corners[i]; Vector2 b = Shape.Corners[i == Shape.Corners.Length - 1 ? 0 : i + 1]; DebugHelpers.DrawCircle(a, Color.cyan, 0.1f); DebugHelpers.DrawCircle(b, Color.cyan, 0.1f); Vector2 ab = (b - a).normalized; Vector2 a1 = a + ab * cornerLength; Vector2 b1 = b - ab * cornerLength; DebugHelpers.DrawCircle(a1, Color.magenta, 0.05f); DebugHelpers.DrawCircle(b1, Color.magenta, 0.05f); float length = Vector2.Distance(a1, b1); float dist = length / (straightFidelity + 1); for (int j = 0; j <= straightFidelity; j++) { Vector2 point = a1 + ab * (dist * j); doThis(index, point); index++; } // curve Vector2 c = Shape.Corners[(i + 2) % Shape.Corners.Length]; Vector2 bc = (c - b).normalized; Vector2 b2 = b + bc * cornerLength; DebugHelpers.DrawCircle(b2, Color.magenta, 0.05f); for (int j = 0; j <= curveFidelity; j++) { float t = j / (float)(curveFidelity + 1); Vector2 point = CalculateBezierPoint(t, b1, b, b, b2); doThis(index, point); index++; } } }
private void OnDrawGizmos() { DebugHelpers.DrawCircle(transform.position, Color.magenta, Radius); }