1 using System.Collections.Generic;
5 namespace droid.Runtime.Utilities.GameObjects.BoundingBoxes {
9 [RequireComponent(typeof(Camera))]
12 List<string> _names =
new List<string>();
13 List<Rect> _rects =
new List<Rect>();
14 Camera _camera = null;
16 [SerializeField]
bool _draw_label =
true;
17 [SerializeField]
BoundingBox[] bounding_boxes = null;
18 [SerializeField]
bool _cache_bounding_boxes =
false;
19 [SerializeField] GUISkin gui_style = null;
20 [SerializeField]
bool _draw_coords =
false;
24 this._camera = this.GetComponent<Camera>();
27 if (!this.gui_style) {
28 this.gui_style = Resources.FindObjectsOfTypeAll<GUISkin>().First(a => a.name ==
"BoundingBox");
31 this.bounding_boxes = FindObjectsOfType<BoundingBox>();
38 if (!this._cache_bounding_boxes) {
39 this.bounding_boxes = FindObjectsOfType<BoundingBox>();
42 foreach (var bb
in this.bounding_boxes) {
43 if (this._camera.WorldToScreenPoint(bb.Bounds.center).z < 0) {
50 this._names.Add(bb.name);
56 GUI.skin = this.gui_style;
65 foreach (var rect
in this._rects) {
67 if (this._draw_label) {
68 text += $
"{this._names[i]}";
71 if (this._draw_coords) {
72 text += $
"\n{rect}\n{rect.center}";
76 a.y = Screen.height - (a.y + a.height);
Rect ScreenSpaceBoundingRect(Camera a_camera, float margin=0f)