Created
March 22, 2024 08:07
-
-
Save baba-s/1b21aded0083da528bb4b3234e5da30f 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 CompositeCollider2DGizmo | |
{ | |
[DrawGizmo | |
( | |
GizmoType.NotInSelectionHierarchy | | |
GizmoType.Selected | | |
GizmoType.NonSelected | |
)] | |
private static void Draw | |
( | |
CompositeCollider2D compositeCollider2D, | |
GizmoType gizmoType | |
) | |
{ | |
var color = Color.red; | |
var width = 8; | |
var transform = compositeCollider2D.transform; | |
var pathCount = compositeCollider2D.pathCount; | |
var points = new List<Vector2>(); | |
Handles.color = color; | |
for ( var i = 0; i < pathCount; i++ ) | |
{ | |
points.Clear(); | |
compositeCollider2D.GetPath( i, points ); | |
points.Add( points[ 0 ] ); | |
Handles.DrawAAPolyLine | |
( | |
lineTex: EditorGUIUtility.whiteTexture, | |
width: width, | |
points: points | |
.Select( x => TransformPointUnscaled( transform, x ) ) | |
.ToArray() | |
); | |
} | |
static Vector3 TransformPointUnscaled | |
( | |
Transform transform, | |
in Vector3 position | |
) | |
{ | |
var localToWorldMatrix = Matrix4x4.TRS | |
( | |
pos: transform.position, | |
q: transform.rotation, | |
s: Vector3.one | |
); | |
return localToWorldMatrix.MultiplyPoint3x4( position ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment