-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathReportBoundsOfSelectedObjects.cs
68 lines (63 loc) · 2.09 KB
/
ReportBoundsOfSelectedObjects.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
namespace EditorFormulas.Formulas
{
public static class ReportBoundsOfSelectedObjects {
[FormulaAttribute ("Report Bounds Of Selected Objects", "Reports the renderer or colliders bounds of the selected objects", "VoxelBoy")]
public static void Run(bool reportRendererBounds, bool reportColliderBounds, bool encapsulateChildren)
{
var selection = Selection.objects;
if(selection.Length == 0) { return; }
foreach(GameObject go in selection)
{
if(reportRendererBounds)
{
var bounds = new Bounds(go.transform.position, Vector3.zero);
var rendererOnObject = go.GetComponent<Renderer>();
if(rendererOnObject != null)
{
bounds = rendererOnObject.bounds;
}
if(encapsulateChildren)
{
var renderersInChildren = go.GetComponentsInChildren<Renderer>();
foreach(var rend in renderersInChildren)
{
bounds.Encapsulate(rend.bounds);
}
}
Debug.Log(string.Format("Renderer bounds of {0} is center:{1} size:{2}",
go.name,
FullVector3String_ReportBoundsOfSelectedObjects(bounds.center),
FullVector3String_ReportBoundsOfSelectedObjects(bounds.size)));
}
if(reportColliderBounds)
{
var bounds = new Bounds(go.transform.position, Vector3.zero);
var colliderOnObject = go.GetComponent<Collider>();
if(colliderOnObject != null)
{
bounds = colliderOnObject.bounds;
}
if(encapsulateChildren)
{
var collidersInChildren = go.GetComponentsInChildren<Collider>();
foreach(var col in collidersInChildren)
{
bounds.Encapsulate(col.bounds);
}
}
Debug.Log(string.Format("Collider bounds of {0} is center:{1} size:{2}",
go.name,
FullVector3String_ReportBoundsOfSelectedObjects(bounds.center),
FullVector3String_ReportBoundsOfSelectedObjects(bounds.size)));
}
}
}
private static string FullVector3String_ReportBoundsOfSelectedObjects(Vector3 vector)
{
return string.Format("({0},{1},{2})", vector.x, vector.y, vector.z);
}
}
}