Skip to content

Instantly share code, notes, and snippets.

@SeanMcTex
Created January 24, 2019 23:43
Show Gist options
  • Save SeanMcTex/d1ec2508f312a42468686db0ec01b228 to your computer and use it in GitHub Desktop.
Save SeanMcTex/d1ec2508f312a42468686db0ec01b228 to your computer and use it in GitHub Desktop.
Unity Utility to display bounds of mesh objects in world space
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
/// <summary>
/// In order to help gauge the size of mesh objects,
/// this script displays the dimensions in world space of a selected object
/// with a MeshRenderer attached whenever it's selected.
/// </summary>
[CustomEditor(typeof(MeshRenderer))]
class MeshMeasure : Editor
{
protected virtual void OnSceneGUI()
{
MeshRenderer meshRenderer = (MeshRenderer)target;
if ( meshRenderer == null)
{
return;
}
GUIStyle style = new GUIStyle();
style.normal.textColor = Color.red;
style.fontStyle = FontStyle.Bold;
style.fontSize = 18;
Vector3 position = meshRenderer.transform.position + Vector3.up * 2f;
Handles.Label(position, meshRenderer.bounds.size.ToString(), style);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment