using System.Collections; using System.Collections.Generic; using UnityEngine; #if UNITY_EDITOR using UnityEditor; #endif [RequireComponent(typeof(BoxCollider2D))] public class BoxCollider2DGizmo : MonoBehaviour { public Color color = new Color(1, 0, 0, 0.5f); #if UNITY_EDITOR private void OnDrawGizmos() { var collider = GetComponent(); Color fill = color; fill.a *= 0.25f; Vector3[] points = new Vector3[4]; Rect r = new Rect(collider.offset - collider.size/2, collider.size); points[0] = transform.TransformPoint(new Vector3(r.min.x, r.min.y)); points[1] = transform.TransformPoint(new Vector3(r.min.x, r.max.y)); points[2] = transform.TransformPoint(new Vector3(r.max.x, r.max.y)); points[3] = transform.TransformPoint(new Vector3(r.max.x, r.min.y)); Handles.DrawSolidRectangleWithOutline(points, fill, color); } #endif }