Created
March 22, 2024 23:40
-
-
Save baba-s/21212cbb73c535f9d7935d639b9fcfd6 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 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