Last active
March 6, 2023 10:30
-
-
Save agermanidis/e4e6050d82bcdc94a6999e59b970c951 to your computer and use it in GitHub Desktop.
Draw Size Gizmo - Unity
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 UnityEngine; | |
using UnityEditor; | |
[ExecuteInEditMode] | |
public class DrawSizeGizmo : MonoBehaviour { | |
public bool enabled = true; | |
void OnDrawGizmos () { | |
if (!enabled) | |
return; | |
Vector3 size = this.GetComponent<Renderer> ().bounds.size; | |
Gizmos.color = Color.red; | |
Gizmos.DrawCube ( | |
transform.position - transform.up * size.y/2f + transform.forward * size.z/2f, | |
new Vector3(size.x, 0.05f, 0.05f) | |
); | |
Handles.Label( | |
transform.position - transform.up * size.y/2f + transform.forward * size.z/2f, | |
size.x.ToString() + "m" | |
); | |
Gizmos.color = Color.green; | |
Gizmos.DrawCube ( | |
transform.position + transform.forward * size.z/2f + transform.right * size.x/2f, | |
new Vector3(0.05f, size.y, 0.05f) | |
); | |
Handles.Label( | |
transform.position + transform.forward * size.z/2f + transform.right * (size.x/2f - 0.1f), | |
size.y.ToString() + "m" | |
); | |
Gizmos.color = Color.blue; | |
Gizmos.DrawCube ( | |
transform.position - transform.up * size.y/2f + transform.right * size.x/2f, | |
new Vector3(0.05f, 0.05f, size.z) | |
); | |
Handles.Label( | |
transform.position - transform.up * size.y/2f + transform.right * (size.x/2f + 0.4f), | |
size.z.ToString() + "m" | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment