Class CurveInteractionCaster
A specialized interaction caster that extends InteractionCasterBase to support curved ray casting. This class implements the IUIModelUpdater interface to facilitate world-space UI interactions based on the generated sample points. It handles complex ray casting scenarios using curves, allowing for a more flexible interaction approach.
Inheritance
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit.Interactors.Casters
Assembly: Unity.XR.Interaction.Toolkit.dll
Syntax
[DisallowMultipleComponent]
[AddComponentMenu("XR/Interactors/Curve Interaction Caster", 22)]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@3.0/api/UnityEngine.XR.Interaction.Toolkit.Interactors.Casters.CurveInteractionCaster.html")]
public class CurveInteractionCaster : InteractionCasterBase, ICurveInteractionCaster, IInteractionCaster, IUIModelUpdater
Remarks
The caster supports different types of hit detection, including sphere and cone casting, alongside the standard ray casting. It allows customization of parameters like the number of curve segments, casting distance, and the size of the casting radius.
Properties
castDistance
Maximum distance for all physics casts.
Declaration
public float castDistance { get; set; }
Property Value
Type | Description |
---|---|
float |
coneCastAngle
Gets or sets the angle in degrees of the cone used for cone casting. Will use regular ray casting if set to 0.
Declaration
public float coneCastAngle { get; set; }
Property Value
Type | Description |
---|---|
float |
hitDetectionType
Gets or sets which type of hit detection to use for the ray cast.
Declaration
public CurveInteractionCaster.HitDetectionType hitDetectionType { get; set; }
Property Value
Type | Description |
---|---|
CurveInteractionCaster.HitDetectionType |
isDestroyed
Indicates whether OnDestroy has been called on this object.
Declaration
protected bool isDestroyed { get; }
Property Value
Type | Description |
---|---|
bool |
lastSamplePoint
Gets the sample point at the last index of samplePoints.
Declaration
public Vector3 lastSamplePoint { get; }
Property Value
Type | Description |
---|---|
Vector3 |
raycastMask
Gets or sets layer mask used for limiting ray cast targets.
Declaration
public LayerMask raycastMask { get; set; }
Property Value
Type | Description |
---|---|
LayerMask |
raycastSnapVolumeInteraction
Whether ray cast should include or ignore hits on trigger colliders that are snap volume colliders, even if the ray cast is set to ignore triggers. If you are not using gaze assistance or XR Interactable Snap Volume components, you should set this property to Ignore to avoid the performance cost.
Declaration
public CurveInteractionCaster.QuerySnapVolumeInteraction raycastSnapVolumeInteraction { get; set; }
Property Value
Type | Description |
---|---|
CurveInteractionCaster.QuerySnapVolumeInteraction |
Remarks
When set to Collide when raycastTriggerInteraction is set to ignore trigger colliders
(when set to Ignore or when set to UseGlobal
while queriesHitTriggers is false),
the ray cast query will be modified to include trigger colliders, but then this behavior will ignore any trigger collider
hits that are not snap volumes.
When set to Ignore when raycastTriggerInteraction is set to hit trigger colliders
(when set to Collide or when set to UseGlobal
while queriesHitTriggers is true),
this behavior will ignore any trigger collider hits that are snap volumes.
See Also
raycastTriggerInteraction
Gets or sets type of interaction with trigger colliders via ray cast.
Declaration
public QueryTriggerInteraction raycastTriggerInteraction { get; set; }
Property Value
Type | Description |
---|---|
QueryTriggerInteraction |
samplePoints
Gets the curve sample points used to determine interaction results.
Declaration
public NativeArray<Vector3> samplePoints { get; protected set; }
Property Value
Type | Description |
---|---|
NativeArray<Vector3> |
sphereCastRadius
Gets or sets radius used for sphere casting.
Declaration
public float sphereCastRadius { get; set; }
Property Value
Type | Description |
---|---|
float |
See Also
targetNumCurveSegments
Gets or sets the number of segments to sample along the curve. This also determines the length of the samplePoints array.
Declaration
public int targetNumCurveSegments { get; set; }
Property Value
Type | Description |
---|---|
int |
Methods
Awake()
See MonoBehaviour.
Declaration
protected override void Awake()
Overrides
CheckCollidersBetweenPoints(in XRInteractionManager, Vector3, Vector3, Vector3, RaycastHit[])
Checks for colliders between specified points using a raycast, sphere cast, or cone cast based on the current configuration. Returns the count of hits detected.
Declaration
protected virtual int CheckCollidersBetweenPoints(in XRInteractionManager interactionManager, Vector3 from, Vector3 to, Vector3 origin, RaycastHit[] raycastHits)
Parameters
Type | Name | Description |
---|---|---|
XRInteractionManager | interactionManager | The XR interaction manager used to help filter colliders |
Vector3 | from | The starting point of the check. |
Vector3 | to | The ending point of the check. |
Vector3 | origin | The origin point for the casting. |
RaycastHit[] | raycastHits | Array to store the results of the raycast hits. |
Returns
Type | Description |
---|---|
int | The number of colliders detected between the given points. |
InitializeCaster()
Tries to initialize the caster.
Declaration
protected override bool InitializeCaster()
Returns
Type | Description |
---|---|
bool | Returns true if successful or already initialized. |
Overrides
OnDestroy()
See MonoBehaviour.
Declaration
protected override void OnDestroy()
Overrides
OnDisable()
See MonoBehaviour.
Declaration
protected virtual void OnDisable()
OnEnable()
See MonoBehaviour.
Declaration
protected virtual void OnEnable()
TryGetColliderTargets(XRInteractionManager, List<Collider>)
Gets an unsorted list of collider targets
Declaration
public override bool TryGetColliderTargets(XRInteractionManager interactionManager, List<Collider> targets)
Parameters
Type | Name | Description |
---|---|---|
XRInteractionManager | interactionManager | XR Interaction manager reference |
List<Collider> | targets | List of target colliders to populate. |
Returns
Type | Description |
---|---|
bool | Returns true if collider targets were found. |
Overrides
TryGetColliderTargets(XRInteractionManager, List<Collider>, List<RaycastHit>)
Tries to get a list of collider targets based on the interaction caster's current state, sorted by their distance from the cast origin.
Declaration
public bool TryGetColliderTargets(XRInteractionManager interactionManager, List<Collider> targets, List<RaycastHit> raycastHits)
Parameters
Type | Name | Description |
---|---|---|
XRInteractionManager | interactionManager | The XR interaction manager. |
List<Collider> | targets | |
List<RaycastHit> | raycastHits | List of raycast hits lined up to the list of colliders. |
Returns
Type | Description |
---|---|
bool | True if targets are successfully detected. |
UpdateInternalData()
Updates internal state for the caster.
Declaration
protected override void UpdateInternalData()
Overrides
UpdatePhysicscastHits(in XRInteractionManager)
Performs physics casting to update hits based on the current sample points. Returns a boolean indicating whether any hits were recorded.
Declaration
protected virtual bool UpdatePhysicscastHits(in XRInteractionManager interactionManager)
Parameters
Type | Name | Description |
---|---|---|
XRInteractionManager | interactionManager | The XR interaction manager used to help filter colliders |
Returns
Type | Description |
---|---|
bool | True if any raycast hits were found; otherwise, false. |
UpdateSamplePoints()
Updates sample points for casting, based on the current, potentially stabilized cast origin and direction.
Declaration
protected virtual void UpdateSamplePoints()
UpdateSamplePoints(in Vector3, in Vector3, float, NativeArray<Vector3>)
Updates a set of sample points for casting, given the origin, direction, total distance, and an array of points. Base implementation does a simple linear interpolation between the origin and the end point.
Declaration
protected virtual void UpdateSamplePoints(in Vector3 origin, in Vector3 direction, float totalDistance, NativeArray<Vector3> points)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | origin | The starting point of the cast. |
Vector3 | direction | The direction in which the cast is performed. |
float | totalDistance | The total distance of the cast. |
NativeArray<Vector3> | points | The array of points to be updated for the cast. |
UpdateUIModel(ref TrackedDeviceModel, bool, in Vector2)
Updates the UI data model based on the implementer of this interface.
Declaration
public bool UpdateUIModel(ref TrackedDeviceModel uiModel, bool isSelectActive, in Vector2 scrollDelta)
Parameters
Type | Name | Description |
---|---|---|
TrackedDeviceModel | uiModel | UI data model to update. |
bool | isSelectActive | UI select input state to write into the UI data model. |
Vector2 | scrollDelta | UI scroll input state to write into the UI data model. |
Returns
Type | Description |
---|---|
bool | Returns true if UI data model was updated successfully. |