summaryrefslogtreecommitdiff
path: root/CollectionProj/Assets/BoundViewer/BoundViewer.cs
blob: e883ba8083c7877ef6e56fa32e8c4f7cb6fe515c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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<MeshFilter>(); 
        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());
        }
    }

}