10 [SerializeField]
private Vector3 _size = Vector3.one;
14 public Vector3
Size {
get => _size;
set => _size = Vector3.Max(value, Vector3.zero); }
16 private void OnValidate()
21 private void OnDrawGizmos()
24 var lineColor = Color.yellow;
25 var fillColor =
new Color(lineColor.r, lineColor.g, lineColor.b, 0.2f);
27 Gizmos.color = fillColor;
28 Gizmos.DrawCube(bounds.center, bounds.size);
29 Gizmos.color = lineColor;
30 Gizmos.DrawWireCube(bounds.center, bounds.size);
38 var size = 0.5f *
Size;
39 var min =
new Vector3(
float.PositiveInfinity,
float.PositiveInfinity,
float.PositiveInfinity);
40 var max =
new Vector3(
float.NegativeInfinity,
float.NegativeInfinity,
float.NegativeInfinity);
42 System.Span<Vector3> corners = stackalloc Vector3[]
44 new Vector3(-1, -1, -1),
45 new Vector3(1, -1, -1),
46 new Vector3(1, 1, -1),
47 new Vector3(-1, 1, -1),
48 new Vector3(-1, -1, 1),
49 new Vector3(1, -1, 1),
51 new Vector3(-1, 1, 1),
54 for (
int i = 0; i < corners.Length; i++)
56 var corner = corners[i];
57 corners[i] =
new Vector3(corner.x * size.x, corner.y * size.y, corner.z * size.z);
60 transform.TransformVectors(corners);
62 foreach (var corner
in corners)
64 min = Vector3.Min(min, corner);
65 max = Vector3.Max(max, corner);
68 return new Bounds(transform.position, max - min);
79 var size = bounds.size;
80 var topLeft = bounds.center - 0.5f * size;
81 var delta = position - topLeft;
82 var x = size.x > 0 ? Mathf.Clamp(delta.x / size.x, 0, 1) : 0.5f;
83 var y = size.y > 0 ? Mathf.Clamp(delta.y / size.y, 0, 1) : 0.5f;
84 var z = size.z > 0 ? Mathf.Clamp(delta.z / size.z, 0, 1) : 0.5f;
85 return new Vector3(x, y, z);
96 var size = bounds.size;
97 var topLeft = bounds.center - 0.5f * size;
98 var bottomRight = topLeft + size;
100 var x = Mathf.Lerp(topLeft.x, bottomRight.x, Mathf.Clamp(parameters.x, 0, 1));
101 var y = Mathf.Lerp(topLeft.y, bottomRight.y, Mathf.Clamp(parameters.y, 0, 1));
102 var z = Mathf.Lerp(topLeft.z, bottomRight.z, Mathf.Clamp(parameters.z, 0, 1));
104 return new Vector3(x, y, z);
An interpolatable area, useful for locating characters moving between door thresholds.
Vector3 InterpolatePosition(Vector3 parameters)
Returns the global position corresponding to the specified interpolation parameters....
Bounds GetAABB()
Returns the axis aligned bounding box for the threshold area.
Vector3 Size
The size of the threshold area.
Vector3 ParameterizePosition(Vector3 position)
Returns the interpolation parameters corresponding to the specified global position....