namespace Zinnia.Cast.Operation.Conversion { using System; using UnityEngine; /// /// Converts between different Physics cast types. /// public abstract class CastConverter : MonoBehaviour { /// /// Converts from . /// /// The optional with customized cast parameters. /// The data. /// The center of the box. /// Half the size of the box in each dimension. /// The direction in which to cast the box. /// The rotation of the box. /// The max length of the cast. /// Whether the BoxCast successfully collides with a valid . public abstract bool ConvertFromBoxCast(PhysicsCast customCast, out RaycastHit hitData, Vector3 center, Vector3 halfExtents, Vector3 direction, Quaternion orientation, float maxDistance); /// /// Converts from . /// /// The optional with customized cast parameters. /// The center of the box. /// Half the size of the box in each dimension. /// The direction in which to cast the box. /// The rotation of the box. /// The max length of the cast. /// A collection of collisions determined by the cast. public abstract ArraySegment ConvertFromBoxCastAll(PhysicsCast customCast, Vector3 center, Vector3 halfExtents, Vector3 direction, Quaternion orientation, float maxDistance); /// /// Converts from . /// /// The optional with customized cast parameters. /// The data. /// The center of the sphere at the start of the capsule. /// The center of the sphere at the end of the capsule. /// The radius of the capsule. /// The direction into which to sweep the capsule. /// The max length of the sweep. /// Whether the CapsuleCast successfully collides with a valid . public abstract bool ConvertFromCapsuleCast(PhysicsCast customCast, out RaycastHit hitData, Vector3 point1, Vector3 point2, float radius, Vector3 direction, float maxDistance); /// /// Converts from . /// /// The optional with customized cast parameters. /// The center of the sphere at the start of the capsule. /// The center of the sphere at the end of the capsule. /// The radius of the capsule. /// The direction into which to sweep the capsule. /// The max length of the sweep. /// A collection of collisions determined by the cast. public abstract ArraySegment ConvertFromCapsuleCastAll(PhysicsCast customCast, Vector3 point1, Vector3 point2, float radius, Vector3 direction, float maxDistance); /// /// Converts from . /// /// The optional with customized cast parameters. /// The data. /// The world position to start the Linecast from. /// The world position to end the Linecast at. /// Whether the Linecast successfully collides with a valid . public abstract bool ConvertFromLinecast(PhysicsCast customCast, out RaycastHit hitData, Vector3 startPosition, Vector3 endPosition); /// /// Converts from . /// /// The optional with customized cast parameters. /// The data. /// The to cast with. /// The maximum length of the . /// Whether the successfully collides with a valid . public abstract bool ConvertFromRaycast(PhysicsCast customCast, out RaycastHit hitData, Ray ray, float maxDistance); /// /// Converts from . /// /// The optional with customized cast parameters. /// The to cast with. /// The maximum length of the . /// A collection of collisions determined by the cast. public abstract ArraySegment ConvertFromRaycastAll(PhysicsCast customCast, Ray ray, float maxDistance); /// /// Converts from . /// /// The optional with customized cast parameters. /// The data. /// The origin point of the sphere to cast. /// The radius of the sphere. /// The direction into which to sweep the sphere. /// The max length of the sweep. /// Whether the SphereCast successfully collides with a valid . public abstract bool ConvertFromSphereCast(PhysicsCast customCast, out RaycastHit hitData, Vector3 origin, float radius, Vector3 direction, float maxDistance); /// /// Converts from . /// /// The optional with customized cast parameters. /// The origin point of the sphere to cast. /// The radius of the sphere. /// The direction into which to sweep the sphere. /// The max length of the sweep. /// A collection of collisions determined by the cast. public abstract ArraySegment ConvertFromSphereCastAll(PhysicsCast customCast, Vector3 origin, float radius, Vector3 direction, float maxDistance); /// /// Gets the direction between two points and also gets the distance. /// /// The starting point. /// The end point. /// The distance between the two points. /// The direction vector between the start and the end point. protected virtual Vector3 GetDirectionVector(Vector3 startPoint, Vector3 endPoint, out float distance) { Vector3 heading = endPoint - startPoint; distance = heading.magnitude; return heading / distance; } /// /// Gets the center point between two vectors. /// /// The first point. /// The second point. /// The central point between the first and second point. protected virtual Vector3 GetCenterVector(Vector3 point1, Vector3 point2) { return (point1 + point2) * 0.5f; } /// /// Gets a point projected from an origin in a given direction at a given distance. /// /// The point to start the projection from. /// The direction to project. /// The distance to project the point at. /// The projected point away from the origin in the given direction at the given distance. protected virtual Vector3 GetProjectedPoint(Vector3 origin, Vector3 direction, float distance) { return origin + (direction * distance); } } }