namespace Zinnia.Cast.Operation.Conversion
{
using System;
using UnityEngine;
///
/// Converts any supported caster to a .
///
public class ToBoxCastConverter : CastConverter
{
[Tooltip("The half extends for the Physics.BoxCast.")]
[SerializeField]
private Vector3 halfExtentsOverride;
///
/// The half extends for the .
///
public Vector3 HalfExtentsOverride
{
get
{
return halfExtentsOverride;
}
set
{
halfExtentsOverride = value;
}
}
[Tooltip("Whether to use the HalfExtentsOverride value if the source caster already supports a half extends. If the source caster does not support a half extends then the HalfExtentsOverride will always be used.")]
[SerializeField]
private bool useHalfExtentsOverride = true;
///
/// Whether to use the value if the source caster already supports a half extends. If the source caster does not support a half extends then the will always be used.
///
public bool UseHalfExtentsOverride
{
get
{
return useHalfExtentsOverride;
}
set
{
useHalfExtentsOverride = value;
}
}
[Tooltip("The orientation for the Physics.BoxCast.")]
[SerializeField]
private Vector3 orientationOverride;
///
/// The orientation for the .
///
public Vector3 OrientationOverride
{
get
{
return orientationOverride;
}
set
{
orientationOverride = value;
}
}
[Tooltip("Whether to use the OrientationOverride value if the source caster already supports a half extends. If the source caster does not support a half extends then the OrientationOverride will always be used.")]
[SerializeField]
private bool useOrientationOverride = true;
///
/// Whether to use the value if the source caster already supports a half extends. If the source caster does not support a half extends then the will always be used.
///
public bool UseOrientationOverride
{
get
{
return useOrientationOverride;
}
set
{
useOrientationOverride = value;
}
}
///
public override bool ConvertFromBoxCast(PhysicsCast customCast, out RaycastHit hitData, Vector3 center, Vector3 halfExtents, Vector3 direction, Quaternion orientation, float maxDistance)
{
return customCast.CustomBoxCast(center, UseHalfExtentsOverride ? HalfExtentsOverride : halfExtents, direction, out hitData, UseOrientationOverride ? Quaternion.Euler(OrientationOverride) : orientation, maxDistance, false);
}
///
public override ArraySegment ConvertFromBoxCastAll(PhysicsCast customCast, Vector3 center, Vector3 halfExtents, Vector3 direction, Quaternion orientation, float maxDistance)
{
return customCast.CustomBoxCastAll(center, UseHalfExtentsOverride ? HalfExtentsOverride : halfExtents, direction, UseOrientationOverride ? Quaternion.Euler(OrientationOverride) : orientation, maxDistance, false);
}
///
public override bool ConvertFromCapsuleCast(PhysicsCast customCast, out RaycastHit hitData, Vector3 point1, Vector3 point2, float radius, Vector3 direction, float maxDistance)
{
Vector3 origin = GetCenterVector(point1, point2);
return customCast.CustomBoxCast(origin, HalfExtentsOverride, direction, out hitData, Quaternion.Euler(OrientationOverride), maxDistance, false);
}
///
public override ArraySegment ConvertFromCapsuleCastAll(PhysicsCast customCast, Vector3 point1, Vector3 point2, float radius, Vector3 direction, float maxDistance)
{
Vector3 origin = GetCenterVector(point1, point2);
return customCast.CustomBoxCastAll(origin, HalfExtentsOverride, direction, Quaternion.Euler(OrientationOverride), maxDistance, false);
}
///
public override bool ConvertFromLinecast(PhysicsCast customCast, out RaycastHit hitData, Vector3 startPosition, Vector3 endPosition)
{
Vector3 direction = GetDirectionVector(startPosition, endPosition, out float distance);
return customCast.CustomBoxCast(startPosition, HalfExtentsOverride, direction, out hitData, Quaternion.Euler(OrientationOverride), distance, false);
}
///
public override bool ConvertFromRaycast(PhysicsCast customCast, out RaycastHit hitData, Ray ray, float maxDistance)
{
return customCast.CustomBoxCast(ray.origin, HalfExtentsOverride, ray.direction, out hitData, Quaternion.Euler(OrientationOverride), maxDistance, false);
}
///
public override ArraySegment ConvertFromRaycastAll(PhysicsCast customCast, Ray ray, float maxDistance)
{
return customCast.CustomBoxCastAll(ray.origin, HalfExtentsOverride, ray.direction, Quaternion.Euler(OrientationOverride), maxDistance, false);
}
///
public override bool ConvertFromSphereCast(PhysicsCast customCast, out RaycastHit hitData, Vector3 origin, float radius, Vector3 direction, float maxDistance)
{
return customCast.CustomBoxCast(origin, HalfExtentsOverride, direction, out hitData, Quaternion.Euler(OrientationOverride), maxDistance, false);
}
///
public override ArraySegment ConvertFromSphereCastAll(PhysicsCast customCast, Vector3 origin, float radius, Vector3 direction, float maxDistance)
{
return customCast.CustomBoxCastAll(origin, HalfExtentsOverride, direction, Quaternion.Euler(OrientationOverride), maxDistance, false);
}
}
}