1 using System.Collections.Generic;
4 namespace droid.Runtime.Utilities.GameObjects.BoundingBoxes {
8 [RequireComponent(typeof(Camera))]
11 List<Color> _colors =
new List<Color>();
12 [SerializeField] Material _line_material;
13 List<GameObject> _names =
new List<GameObject>();
15 List<Vector3[,]> _outlines =
new List<Vector3[,]>();
21 [SerializeField]
bool _draw_label =
true;
23 [SerializeField]
bool _cacheBoundingBoxes =
true;
26 if (!this._line_material) {
27 var shader = Shader.Find(
"Unlit/Color");
28 this._line_material =
new Material(shader);
33 this._camera = this.GetComponent<Camera>();
37 if (this._outlines == null) {
41 if (this._line_material) {
42 this._line_material.SetPass(0);
46 for (var j = 0; j < this._outlines.Count; j++) {
47 GL.Color(this._colors[j]);
48 for (var i = 0; i < this._outlines[j].GetLength(0); i++) {
49 GL.Vertex(this._outlines[j][i, 0]);
50 GL.Vertex(this._outlines[j][i, 1]);
76 public void SetOutlines(Vector3[,] new_outlines, Color new_color, GameObject game_object) {
77 if (new_outlines == null) {
81 if (this._outlines == null) {
85 if (new_outlines.GetLength(0) > 0) {
86 this._outlines.Add(new_outlines);
87 this._colors.Add(new_color);
88 this._names.Add(game_object);
115 this._outlines.Clear();
116 this._colors.Clear();
119 if (!this._cacheBoundingBoxes || this._bounding_boxes == null || this._bounding_boxes.Length == 0) {
120 this._bounding_boxes = FindObjectsOfType<BoundingBox>();
123 foreach (var bb
in this._bounding_boxes) {
125 this.SetOutlines(bb.Lines, bb.EditorPreviewLineColor, bb.gameObject);
130 const float _padding = 4;
133 if (this._draw_label) {
135 foreach (var t
in this._outlines) {
137 var box_position = this._camera.WorldToScreenPoint(point);
138 box_position.y = Screen.height - box_position.y;
140 var text = this._names[i].name;
142 var content = GUI.skin.box.CalcSize(
new GUIContent(text));
143 content.x = content.x + _padding;
144 content.y = content.y + _padding;
145 var rect =
new Rect(box_position.x - content.x / 2,
146 box_position.y - content.y / 2,
void SetOutlines(Vector3[,] new_outlines, Color new_color, GameObject game_object)