-
Notifications
You must be signed in to change notification settings - Fork 5
/
MeshBoundsGizmo.cs
53 lines (43 loc) · 993 Bytes
/
MeshBoundsGizmo.cs
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
* Display the mesh bounds as a gizmo. Because there's no built in way to do so
*/
[RequireComponent(typeof(MeshFilter))]
public class MeshBoundsGizmo : MonoBehaviour {
public Color Colour = Color.red;
[ShowFunctionResult("GetBoundsMin")]
public bool _Min;
[ShowFunctionResult("GetBoundsMax")]
public bool _Max;
Vector3 GetBoundsMin()
{
var mf = GetComponent<MeshFilter>();
var m = mf.sharedMesh;
var b = m.bounds;
return b.min;
}
Vector3 GetBoundsMax()
{
var mf = GetComponent<MeshFilter>();
var m = mf.sharedMesh;
var b = m.bounds;
return b.max;
}
// to enable the enable checkbox
void Update()
{
}
void OnDrawGizmos()
{
if (!this.enabled)
return;
var mf = GetComponent<MeshFilter>();
var m = mf.sharedMesh;
var b = m.bounds;
Gizmos.matrix = this.transform.localToWorldMatrix;
Gizmos.color = Colour;
Gizmos.DrawWireCube(b.center, b.size);
}
}