Class InteractionCasterBase
Provides an abstract base for interaction casters used by NearFarInteractor. This class serves as the foundation for casting interactions, managing initialization, and providing the fundamental mechanics for casting. It implements the IInteractionCaster interface.
Implements
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit.Interactors.Casters
Assembly: Unity.XR.Interaction.Toolkit.dll
Syntax
public abstract class InteractionCasterBase : MonoBehaviour, IInteractionCaster
Remarks
The class maintains a state to track whether it has been initialized and allows for setting and getting the origin of casting. It also requires implementation of an abstract method to try and get collider targets based on an XRInteractionManager.
Properties
aimTarget
Gets or sets the aim target ray provider for calculating stable rotation.
Declaration
public IXRRayProvider aimTarget { get; set; }
Property Value
Type | Description |
---|---|
IXRRayProvider |
angleStabilization
Factor for stabilizing angle. This value represents the maximum angle (in degrees) over which angle stabilization will be applied. Larger values increase the range of stabilization, making the effect more pronounced over a greater angle.
Declaration
public float angleStabilization { get; set; }
Property Value
Type | Description |
---|---|
float |
castOrigin
Source of origin and direction used when updating sample points.
Declaration
public Transform castOrigin { get; set; }
Property Value
Type | Description |
---|---|
Transform |
effectiveCastOrigin
Gets the effective cast origin, which may be different than the castOrigin. The caster may use a different transform, such as one that is stabilized, to conduct the cast.
Declaration
public Transform effectiveCastOrigin { get; }
Property Value
Type | Description |
---|---|
Transform |
enableStabilization
Determines whether to stabilize the cast origin.
Declaration
public bool enableStabilization { get; set; }
Property Value
Type | Description |
---|---|
bool |
isInitialized
Indicates whether the caster has been initialized.
Declaration
public bool isInitialized { get; protected set; }
Property Value
Type | Description |
---|---|
bool |
positionStabilization
Factor for stabilizing position. This value represents the maximum distance (in meters) over which position stabilization will be applied. Larger values increase the range of stabilization, making the effect more pronounced over a greater distance.
Declaration
public float positionStabilization { get; set; }
Property Value
Type | Description |
---|---|
float |
Methods
Awake()
See MonoBehaviour.
Declaration
protected virtual void Awake()
InitializeCaster()
Tries to initialize the caster.
Declaration
protected abstract bool InitializeCaster()
Returns
Type | Description |
---|---|
bool | Returns true if successful or already initialized. |
InitializeStabilization()
Creates a stabilization anchor if one does not already exist.
Declaration
protected virtual bool InitializeStabilization()
Returns
Type | Description |
---|---|
bool | True if anchor exists or stabilization is disabled |
OnDestroy()
See MonoBehaviour.
Declaration
protected virtual void OnDestroy()
OnValidate()
See MonoBehaviour.
Declaration
protected virtual void OnValidate()
TryGetColliderTargets(XRInteractionManager, List<Collider>)
Gets an unsorted list of collider targets
Declaration
public virtual 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. |
UpdateInternalData()
Updates internal state for the caster.
Declaration
protected virtual void UpdateInternalData()