You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
718 B

4 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public static class GameObjectExtensions
  5. {
  6. /// <summary>
  7. /// Retourns the bounds of all colliders in a gameobject
  8. /// </summary>
  9. /// <param name="gameObject">Gameobject to get bounds of</param>
  10. /// <returns>Bounds of gameobject</returns>
  11. public static Bounds GetBounds(this GameObject gameObject)
  12. {
  13. Bounds bounds = new Bounds(gameObject.transform.position, Vector3.zero);
  14. Collider[] colliders = gameObject.GetComponentsInChildren<Collider>();
  15. foreach (Collider col in colliders)
  16. {
  17. bounds.Encapsulate(col.bounds);
  18. }
  19. return bounds;
  20. }
  21. }