Created
March 22, 2024 23:54
-
-
Save baba-s/53cbf56f67e65370309a70ac44d255de 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.Linq; | |
using UnityEditor; | |
using UnityEngine; | |
namespace Kogane.Internal | |
{ | |
internal static class BoxCollider2DGizmo | |
{ | |
[DrawGizmo | |
( | |
GizmoType.NotInSelectionHierarchy | | |
GizmoType.Selected | | |
GizmoType.NonSelected | |
)] | |
private static void Draw | |
( | |
BoxCollider2D boxCollider2D, | |
GizmoType gizmoType | |
) | |
{ | |
var color = Color.red; | |
var width = 8; | |
var transform = boxCollider2D.transform; | |
var offset = boxCollider2D.offset; | |
var size = boxCollider2D.size; | |
var p1 = offset + new Vector2( -size.x, -size.y ) * 0.5f; | |
var p2 = offset + new Vector2( size.x, -size.y ) * 0.5f; | |
var p3 = offset + new Vector2( size.x, size.y ) * 0.5f; | |
var p4 = offset + new Vector2( -size.x, size.y ) * 0.5f; | |
var points = new[] { p1, p2, p3, p4, p1, p2, }; | |
Handles.color = color; | |
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