|
| 1 | +/** |
| 2 | + * $File: JCS_Bounds.cs $ |
| 3 | + * $Date: $ |
| 4 | + * $Revision: $ |
| 5 | + * $Creator: Jen-Chieh Shen $ |
| 6 | + * $Notice: See LICENSE.txt for modification and distribution information |
| 7 | + * Copyright (c) 2025 by Shen, Jen-Chieh $ |
| 8 | + */ |
| 9 | +using UnityEngine; |
| 10 | + |
| 11 | +namespace JCSUnity |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Bounds util. |
| 15 | + /// </summary> |
| 16 | + public static class JCS_Bounds |
| 17 | + { |
| 18 | + /* Variables */ |
| 19 | + |
| 20 | + /* Setter & Getter */ |
| 21 | + |
| 22 | + /* Functions */ |
| 23 | + |
| 24 | + /// <summary> |
| 25 | + /// Return 8 corners from the bounds. |
| 26 | + /// </summary> |
| 27 | + /// <param name="bounds"> The bounds to get from. </param> |
| 28 | + public static Vector3[] Corners(Bounds bounds) |
| 29 | + { |
| 30 | + Vector3 center = bounds.center; |
| 31 | + Vector3 extents = bounds.extents; |
| 32 | + |
| 33 | + return new Vector3[] |
| 34 | + { |
| 35 | + center + new Vector3(-extents.x, -extents.y, -extents.z), // Bottom-back-left |
| 36 | + center + new Vector3(extents.x, -extents.y, -extents.z), // Bottom-back-right |
| 37 | + center + new Vector3(-extents.x, -extents.y, extents.z), // Bottom-front-left |
| 38 | + center + new Vector3(extents.x, -extents.y, extents.z), // Bottom-front-right |
| 39 | + center + new Vector3(-extents.x, extents.y, -extents.z), // Top-back-left |
| 40 | + center + new Vector3(extents.x, extents.y, -extents.z), // Top-back-right |
| 41 | + center + new Vector3(-extents.x, extents.y, extents.z), // Top-front-left |
| 42 | + center + new Vector3(extents.x, extents.y, extents.z) // Top-front-right |
| 43 | + }; |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments