Class XRInputValueReader<TValue>
Serializable typed input value reader that can read the current value from an input source. Behaviors can declare a field of this type to allow them to read input from an input action or any other source.
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit.Inputs.Readers
Assembly: Unity.XR.Interaction.Toolkit.dll
Syntax
[Serializable]
public class XRInputValueReader<TValue> : XRInputValueReader, IXRInputValueReader<TValue>, IXRInputValueReader where TValue : struct
Type Parameters
Name | Description |
---|---|
TValue |
Constructors
XRInputValueReader()
Initializes and returns an instance of XRInputValueReader<TValue>.
Declaration
public XRInputValueReader()
XRInputValueReader(string, InputSourceMode)
Initializes and returns an instance of XRInputValueReader<TValue>.
Declaration
public XRInputValueReader(string name = null, XRInputValueReader.InputSourceMode inputSourceMode = InputSourceMode.InputActionReference)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the directly serialized embedded input action. |
XRInputValueReader.InputSourceMode | inputSourceMode | The initial input source mode. |
Properties
bypass
A runtime bypass that can be used to override the input value returned by this class.
Declaration
public IXRInputValueReader<TValue> bypass { get; set; }
Property Value
Type | Description |
---|---|
IXRInputValueReader<TValue> |
manualValue
The manually set value that is returned when the mode is set to ManualValue.
Declaration
public TValue manualValue { get; set; }
Property Value
Type | Description |
---|---|
TValue |
Methods
GetObjectReference()
Gets the object reference that is used as the input source when the mode is set to ObjectReference.
Declaration
public IXRInputValueReader<TValue> GetObjectReference()
Returns
Type | Description |
---|---|
IXRInputValueReader<TValue> | Returns the typed object reference, which may be null. |
ReadValue()
Read the current value from the input source.
Declaration
public TValue ReadValue()
Returns
Type | Description |
---|---|
TValue | Returns the current value from the input source. May return |
SetObjectReference(IXRInputValueReader<TValue>)
Sets the object reference that is used as the input source when the mode is set to ObjectReference.
Declaration
public void SetObjectReference(IXRInputValueReader<TValue> value)
Parameters
Type | Name | Description |
---|---|---|
IXRInputValueReader<TValue> | value | The typed object reference. |
Remarks
If the argument is to be serialized, it must be a Unity Object type.
TryReadValue(out TValue)
Try to read the current value from the input source.
Declaration
public bool TryReadValue(out TValue value)
Parameters
Type | Name | Description |
---|---|---|
TValue | value | When this method returns, contains the current value from the input source. May return |
Returns
Type | Description |
---|---|
bool | Returns true if the current value was able to be read (and for actions, also if in progress). |
Remarks
You can use the return value of this method instead of only using ReadValue() in order to avoid doing
any work when the input action is not in progress, such as when the control is not actuated.
This can be useful for performance reasons.
If an input processor on an input action returns a different value from the default TValue
when the input action is not in progress, the outvalue
returned by
this method may not be default(TValue)
as is typically the case for Try
- methods. If you need
to support processors that return a different value from the default when the control is not actuated,
you should use ReadValue() instead of using the return value of this method to skip input handling.