From 61f7041fd10f1545991e6fbc66ade10c6835c5a4 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 10 May 2021 21:35:08 +0800 Subject: +misc --- .../Assets/Tools/BoundViewer/BoundViewer.cs | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 CollectionProj/Assets/Tools/BoundViewer/BoundViewer.cs (limited to 'CollectionProj/Assets/Tools/BoundViewer/BoundViewer.cs') diff --git a/CollectionProj/Assets/Tools/BoundViewer/BoundViewer.cs b/CollectionProj/Assets/Tools/BoundViewer/BoundViewer.cs new file mode 100644 index 0000000..e883ba8 --- /dev/null +++ b/CollectionProj/Assets/Tools/BoundViewer/BoundViewer.cs @@ -0,0 +1,34 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BoundViewer : MonoBehaviour +{ + + private Mesh m_Mesh; + + private void OnEnable() + { + if (m_Mesh != null) + return; + MeshFilter renderer = GetComponentInChildren(); + if(renderer) + { + m_Mesh = renderer.sharedMesh; + } + } + + public void OnDrawGizmos() + { + OnEnable(); + if (m_Mesh != null) + { + Bounds bound = m_Mesh.bounds; + bound.center = Vector3.Scale(bound.center, transform.localScale) + transform.position; + bound.size = Vector3.Scale(bound.size, transform.localScale); + Gizmos.DrawWireCube(bound.center, bound.size); + UnityEditor.Handles.Label(transform.position, bound.size.ToString()); + } + } + +} -- cgit v1.1-26-g67d0