Created
January 24, 2019 23:43
-
-
Save SeanMcTex/d1ec2508f312a42468686db0ec01b228 to your computer and use it in GitHub Desktop.
Unity Utility to display bounds of mesh objects in world space
This file contains 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.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