IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
DrawBounds.cs
1 using UnityEngine;
2 using System.Collections;
3 using System.Collections.Generic;
4 
5 public class DrawBounds : MonoBehaviour {
6 
7  // Use this for initialization
8  void Start () {
9 
10  }
11 
12  // Update is called once per frame
13  void Update () {
14 
15  }
16 
17  public bool _bIsSelected = true;
18 
19  void OnDrawGizmos()
20  {
21  if (_bIsSelected)
22  OnDrawGizmosSelected();
23  }
24 
25 
26  void OnDrawGizmosSelected()
27  {
28  Gizmos.color = Color.yellow;
29  Gizmos.DrawSphere(transform.position, 0.1f); //center sphere
30  if (transform.GetComponent<Renderer> () != null)
31  Gizmos.DrawWireCube (transform.GetComponent<Renderer> ().bounds.center, transform.GetComponent<Renderer> ().bounds.size);
32  else {
33  Bounds bounds = new Bounds ();
34  bool boundsInitialized = false;
35  Renderer[] renderers = GetComponentsInChildren<Renderer> ();
36  foreach (Renderer r in renderers) {
37  if (!boundsInitialized) {
38  bounds = r.bounds;
39  boundsInitialized = true;
40  } else {
41  bounds.Encapsulate (r.bounds);
42  }
43  }
44 
45  Gizmos.DrawWireCube (bounds.center, bounds.size);
46  }
47  }
48 }