Skip to content

Instantly share code, notes, and snippets.

@baba-s
Created March 22, 2024 23:40
Show Gist options
  • Save baba-s/21212cbb73c535f9d7935d639b9fcfd6 to your computer and use it in GitHub Desktop.
Save baba-s/21212cbb73c535f9d7935d639b9fcfd6 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace Kogane.Internal
{
internal static class PolygonCollider2DGizmo
{
[DrawGizmo
(
GizmoType.NotInSelectionHierarchy |
GizmoType.Selected |
GizmoType.NonSelected
)]
private static void Draw
(
PolygonCollider2D polygonCollider2D,
GizmoType gizmoType
)
{
var color = Color.red;
var width = 8;
var transform = polygonCollider2D.transform;
var pathCount = polygonCollider2D.pathCount;
var points = new List<Vector2>();
Handles.color = color;
for ( var i = 0; i < pathCount; i++ )
{
points.Clear();
polygonCollider2D.GetPath( i, points );
points.Add( points[ 0 ] );
Handles.DrawAAPolyLine
(
lineTex: EditorGUIUtility.whiteTexture,
width: width,
points: points
.Select( x => transform.TransformPoint( x ) )
.ToArray()
);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment