Created
March 23, 2024 00:05
-
-
Save baba-s/1ffc5a83411043c649425484331f0814 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
namespace Kogane.Internal | |
{ | |
internal static class CircleCollider2DGizmo | |
{ | |
[DrawGizmo | |
( | |
GizmoType.NotInSelectionHierarchy | | |
GizmoType.Selected | | |
GizmoType.NonSelected | |
)] | |
private static void Draw | |
( | |
CircleCollider2D circleCollider2D, | |
GizmoType gizmoType | |
) | |
{ | |
var color = Color.red; | |
var width = 8; | |
var segments = 90; | |
var transform = circleCollider2D.transform; | |
var offset = circleCollider2D.offset; | |
var radius = circleCollider2D.radius; | |
var points = new Vector3[ segments ]; | |
for ( var i = 0; i < segments; i++ ) | |
{ | |
var f = Mathf.Deg2Rad * ( i * 360f / ( segments - 1 ) ); | |
var x = offset.x + Mathf.Sin( f ) * radius; | |
var y = offset.y + Mathf.Cos( f ) * radius; | |
points[ i ] = transform.TransformPoint( new Vector3( x, y ) ); | |
} | |
Handles.color = color; | |
Handles.DrawAAPolyLine | |
( | |
lineTex: EditorGUIUtility.whiteTexture, | |
width: width, | |
points: points | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment