docs.unity3d.com
    Show / Hide Table of Contents

    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.

    Inheritance
    Object
    XRTargetEvaluator
    XRAngleGazeEvaluator
    XRDistanceEvaluator
    XRLastSelectedEvaluator
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    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
    Dispose()

    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
    GetWeightedScore(IXRInteractor, IXRInteractable)

    Methods

    Awake()

    Unity calls this automatically when the evaluator instance is being loaded.

    Declaration
    protected virtual void Awake()
    See Also
    AddEvaluator(Type)
    AddEvaluator<T>()

    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.
    It's a good practice to return a value between 0 and 1 inclusive and edit the weight curve to evaluate the target weighted interaction score.

    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
    XRTargetFilter
    GetValidTargets(List<IXRInteractable>)

    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
    IDisposable.Dispose()
    See Also
    Process(IXRInteractor, List<IXRInteractable>, List<IXRInteractable>)

    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 1.
    You can configure the returned value of this method by editing the weight curve in the Inspector.
    Returns 1 if the intention is to select the given target.
    Returns 0 if the intention is to not select the given target. This will stop the evaluation process for the given target.
    Returns a negative value to exclude the given target from the list of targets for interaction.

    See Also
    XRTargetFilter
    GetValidTargets(List<IXRInteractable>)

    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
    enabled

    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
    Dispose()
    RemoveEvaluator(XRTargetEvaluator)
    RemoveEvaluatorAt(Int32)

    OnEnable()

    Unity calls this automatically when the evaluator becomes enabled and active.

    Declaration
    protected virtual void OnEnable()
    See Also
    enabled

    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()

    See Also

    XRAngleGazeEvaluator
    XRDistanceEvaluator
    XRLastSelectedEvaluator
    IXRTargetEvaluatorLinkable
    XRTargetFilter
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023