Example code that draws a line on top of the top of a BoxCollider2D in a custom editor:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(SomeBehaviour))]
public class SomeInspector : Editor
{
public void OnSceneGUI()
{
var bounds = ((SomeBehaviour)target).GetComponent<BoxCollider2D>().bounds;
float z = 0f;
Handles.color = Color.blue;
Handles.DrawLine(new Vector3(bounds.min.x, bounds.max.y, z), new Vector3(bounds.max.x, bounds.max.y, z));
}
}
using UnityEngine;
[RequireComponent(typeof(BoxCollider2D))]
public class SomeBehaviour : MonoBehaviour
{
}
Draws on top of gizmos wireframe as it should regardless of component order:
Does not draw on top of handles in edit mode if BoxCollider2D is placed below SomeBehaviour:
How can I draw on top of handles in edit mode regardless of component order?