-
Notifications
You must be signed in to change notification settings - Fork 450
/
Copy pathDrawRendererBounds.cs
49 lines (40 loc) · 1.49 KB
/
DrawRendererBounds.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
using UnityEngine;
// draws mesh renderer bounding box using Debug.Drawline
namespace UnityLibrary
{
public class DrawRendererBounds : MonoBehaviour
{
MeshRenderer meshRenderer;
void Awake()
{
meshRenderer = GetComponent<MeshRenderer>();
}
void Update()
{
var b = meshRenderer.bounds;
// bottom
var p1 = new Vector3(b.min.x, b.min.y, b.min.z);
var p2 = new Vector3(b.max.x, b.min.y, b.min.z);
var p3 = new Vector3(b.max.x, b.min.y, b.max.z);
var p4 = new Vector3(b.min.x, b.min.y, b.max.z);
Debug.DrawLine(p1, p2, Color.blue);
Debug.DrawLine(p2, p3, Color.red);
Debug.DrawLine(p3, p4, Color.yellow);
Debug.DrawLine(p4, p1, Color.magenta);
// top
var p5 = new Vector3(b.min.x, b.max.y, b.min.z);
var p6 = new Vector3(b.max.x, b.max.y, b.min.z);
var p7 = new Vector3(b.max.x, b.max.y, b.max.z);
var p8 = new Vector3(b.min.x, b.max.y, b.max.z);
Debug.DrawLine(p5, p6, Color.blue);
Debug.DrawLine(p6, p7, Color.red);
Debug.DrawLine(p7, p8, Color.yellow);
Debug.DrawLine(p8, p5, Color.magenta);
// sides
Debug.DrawLine(p1, p5, Color.white);
Debug.DrawLine(p2, p6, Color.gray);
Debug.DrawLine(p3, p7, Color.green);
Debug.DrawLine(p4, p8, Color.cyan);
}
}
}