Skip to content

Instantly share code, notes, and snippets.

@BanksySan
Last active April 22, 2020 21:10
Show Gist options
  • Save BanksySan/e30638246eb95d8f34b402327ed8b40e to your computer and use it in GitHub Desktop.
Save BanksySan/e30638246eb95d8f34b402327ed8b40e to your computer and use it in GitHub Desktop.
Blog - Mark Center andExtents
using UnityEngine;
using static UnityEditor.Handles;
using static UnityEngine.Color;
using static UnityEngine.Gizmos;
[ExecuteAlways]
[RequireComponent(typeof(Renderer))]
public class MarkCenterAndExtents : MonoBehaviour
{
private const float RADIUS = 0.02f;
private GUIStyle _labelStyle;
private Renderer _renderer;
private void Start()
{
_renderer = GetComponent<Renderer>();
_labelStyle = new GUIStyle
{
fontSize = 40,
fontStyle = FontStyle.Bold,
contentOffset = new Vector2(20, 0)
};
}
private void OnDrawGizmos()
{
var bounds = _renderer.bounds;
Gizmos.color = white;
Vector2 center = bounds.center;
DrawSphere(center, RADIUS);
Label(center, $"Centre: {center}", _labelStyle);
Gizmos.color = red;
Vector2 extents = bounds.extents;
DrawSphere(extents, RADIUS);
Label(extents, $"Extent: {extents}", _labelStyle);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment