Class XRTargetEvaluator
Abstract base class from which all Target Evaluators derive.
This class evaluates the intention to interact with an Interactable by calculating a score (a float
value).
Used by the XRTargetFilter behavior which allows the list of valid targets returned by an Interactor
to be customized as determined by these evaluators.
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit.Filtering
Syntax
[Serializable]
public abstract class XRTargetEvaluator : IDisposable
Remarks
All virtual and abstract methods in this class (Awake(), OnDispose(), OnEnable(), OnDisable(), Reset(), and CalculateNormalizedScore(IXRInteractor, IXRInteractable)) are designed to be called at specific moments and you shouldn't manually call them.
Properties
disposed
(Read Only) Whether this evaluator was disposed. A disposed Target Evaluator has no use and you should not keep a reference to it.
Declaration
public bool disposed { get; }
Property Value
Type | Description |
---|---|
Boolean |
See Also
enabled
Whether this Target Evaluator is enabled. Enabled evaluators are processed by its filter, disabled evaluators are not.
Declaration
public bool enabled { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
You cannot disable an evaluator while its filter is processing. If the evaluator becomes enabled while the filter is processing, it'll only participate from the next filtering process.
filter
(Read Only) The XRTargetFilter that owns this Target Evaluator.
Declaration
public XRTargetFilter filter { get; }
Property Value
Type | Description |
---|---|
XRTargetFilter |
weight
The weight curve of this evaluator. Use this curve to configure the returned value of the GetWeightedScore(IXRInteractor, IXRInteractable) method.
Declaration
public AnimationCurve weight { get; set; }
Property Value
Type | Description |
---|---|
AnimationCurve |
Remarks
The x-axis is the normalized score (calculated in CalculateNormalizedScore(IXRInteractor, IXRInteractable)) and the y-axis is the returned weighted score of this evaluator (in GetWeightedScore(IXRInteractor, IXRInteractable)).
See Also
Methods
Awake()
Unity calls this automatically when the evaluator instance is being loaded.
Declaration
protected virtual void Awake()
See Also
CalculateNormalizedScore(IXRInteractor, IXRInteractable)
Calculates and returns a normalized value that represents the intention to select the given target Interactable.
The highest score of 1
represents the intention to select the given target and the lowest score of 0
the intention to not select it, any value in between is valid.
Declaration
protected abstract float CalculateNormalizedScore(IXRInteractor interactor, IXRInteractable target)
Parameters
Type | Name | Description |
---|---|---|
IXRInteractor | interactor | The Interactor whose Interactable targets (candidates) are being evaluated. |
IXRInteractable | target | The target Interactable to evaluate the normalized score. |
Returns
Type | Description |
---|---|
Single | Returns the normalized interaction score of the given target.
|
Remarks
The returned normalized score is evaluated by the weight curve (in GetWeightedScore(IXRInteractor, IXRInteractable)) and then
(in Process(IXRInteractor, List<IXRInteractable>, List<IXRInteractable>)) it's multiplied by the other evaluator weighted score in the same filter
to get the target final score.
You cannot disable, remove, or dispose evaluators from the filter in this method.
You also cannot unlink Interactors from the filter in this method.
See Also
Dispose()
Call this to dispose this Target Evaluator. This removes the evaluator from its filter. After this call the evaluator has no use and you should not keep a reference to it.
Declaration
public void Dispose()
Implements
See Also
GetWeightedScore(IXRInteractor, IXRInteractable)
The filter calls this method to get a value that represents the intention to select the given target Interactable. Gets the weighted interaction score, the y-axis value in the weight curve for an x-axis value returned by CalculateNormalizedScore(IXRInteractor, IXRInteractable).
Declaration
public float GetWeightedScore(IXRInteractor interactor, IXRInteractable target)
Parameters
Type | Name | Description |
---|---|---|
IXRInteractor | interactor | The Interactor whose Interactable targets (candidates) are being evaluated. |
IXRInteractable | target | The Interactable to evaluate the weighted score. |
Returns
Type | Description |
---|---|
Single | Returns the weighted interaction score of the given target. Usually a normalized value but it can be negative and more than |
See Also
OnDisable()
Unity calls this automatically when the evaluator becomes disabled. Use this method for any code cleanup. This is also called when the evaluator is disposed or when its filter is destroyed or disabled.
Declaration
protected virtual void OnDisable()
Remarks
When scripts are reloaded after compilation has finished, OnDisable
will be called, followed by OnEnable
after the evaluator has been loaded.
OnDisable
will only be called if a call to OnEnable() happened before.
See Also
OnDispose()
Unity calls this automatically when the evaluator is being disposed. This is also called when the evaluator filter is destroyed.
Declaration
protected virtual void OnDispose()
Remarks
OnDispose
will only be called if a call to Awake() happened before.
See Also
OnEnable()
Unity calls this automatically when the evaluator becomes enabled and active.
Declaration
protected virtual void OnEnable()
See Also
Reset()
(Editor Only) Unity calls this automatically when adding the evaluator to the Filter Target the first time. This function is only called in the Unity editor. Reset is most commonly used to give good default values in the Inspector.
Declaration
public virtual void Reset()