using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Scripting;
namespace UnityEngine.XR.Interaction.Toolkit.Inputs.Composites
{
///
/// A single value, such as a position, computed from an ordered list of bindings.
/// Unity reads from the first binding that has a valid control.
///
///
#if UNITY_EDITOR
[InitializeOnLoad]
#endif
[Preserve]
public class Vector3FallbackComposite : FallbackComposite
{
///
/// The first input control to evaluate.
///
[InputControl(layout = "Vector3")]
public int first;
///
/// The second input control to evaluate.
///
[InputControl(layout = "Vector3")]
public int second;
///
/// The third input control to evaluate.
///
[InputControl(layout = "Vector3")]
public int third;
///
/// See
///
/// Callback context for the binding composite. Unity
/// uses this to access the values supplied by part bindings.
/// read from the context.
public override Vector3 ReadValue(ref InputBindingCompositeContext context)
{
var value = context.ReadValue(first, out var sourceControl);
if (sourceControl != null)
return value;
value = context.ReadValue(second, out sourceControl);
if (sourceControl != null)
return value;
value = context.ReadValue(third);
return value;
}
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad), Preserve]
#pragma warning disable IDE0051 // Remove unused private members
// ReSharper disable once UnusedMember.Local
static void Initialize()
#pragma warning restore IDE0051
{
// Will execute the static constructor as a side effect.
}
[Preserve]
static Vector3FallbackComposite()
{
InputSystem.InputSystem.RegisterBindingComposite();
}
}
///
/// A single value, such as a rotation, computed from an ordered list of bindings.
/// Unity reads from the first binding that has a valid control.
///
///
#if UNITY_EDITOR
[InitializeOnLoad]
#endif
[Preserve]
public class QuaternionFallbackComposite : FallbackComposite
{
///
/// The first input control to evaluate.
///
[InputControl(layout = "Quaternion")]
public int first;
///
/// The second input control to evaluate.
///
[InputControl(layout = "Quaternion")]
public int second;
///
/// The third input control to evaluate.
///
[InputControl(layout = "Quaternion")]
public int third;
///
/// See
///
/// Callback context for the binding composite. Unity
/// uses this to access the values supplied by part bindings.
/// read from the context.
public override Quaternion ReadValue(ref InputBindingCompositeContext context)
{
var value = context.ReadValue(first, out var sourceControl);
if (sourceControl != null)
return value;
value = context.ReadValue(second, out sourceControl);
if (sourceControl != null)
return value;
value = context.ReadValue(third);
return value;
}
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad), Preserve]
#pragma warning disable IDE0051 // Remove unused private members
// ReSharper disable once UnusedMember.Local
static void Initialize()
#pragma warning restore IDE0051
{
// Will execute the static constructor as a side effect.
}
[Preserve]
static QuaternionFallbackComposite()
{
InputSystem.InputSystem.RegisterBindingComposite();
}
}
///
/// A single value, such as the tracking state, computed from an ordered list of bindings.
/// Unity reads from the first binding that has a valid control.
///
///
#if UNITY_EDITOR
[InitializeOnLoad]
#endif
[Preserve]
public class IntegerFallbackComposite : FallbackComposite
{
///
/// The first input control to evaluate.
///
[InputControl(layout = "Integer")]
public int first;
///
/// The second input control to evaluate.
///
[InputControl(layout = "Integer")]
public int second;
///
/// The third input control to evaluate.
///
[InputControl(layout = "Integer")]
public int third;
///
/// See
///
/// Callback context for the binding composite. Unity
/// uses this to access the values supplied by part bindings.
/// read from the context.
public override int ReadValue(ref InputBindingCompositeContext context)
{
var value = context.ReadValue(first, out var sourceControl);
if (sourceControl != null)
return value;
value = context.ReadValue(second, out sourceControl);
if (sourceControl != null)
return value;
value = context.ReadValue(third);
return value;
}
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad), Preserve]
#pragma warning disable IDE0051 // Remove unused private members
// ReSharper disable once UnusedMember.Local
static void Initialize()
#pragma warning restore IDE0051
{
// Will execute the static constructor as a side effect.
}
[Preserve]
static IntegerFallbackComposite()
{
InputSystem.InputSystem.RegisterBindingComposite();
}
}
///
/// A single Button value, such as the is tracked state, computed from an ordered list of bindings.
/// Unity reads from the first binding that has a valid control.
///
///
#if UNITY_EDITOR
[InitializeOnLoad]
#endif
[Preserve]
public class ButtonFallbackComposite : FallbackComposite
{
///
/// The first input control to evaluate.
///
[InputControl(layout = "Button")]
public int first;
///
/// The second input control to evaluate.
///
[InputControl(layout = "Button")]
public int second;
///
/// The third input control to evaluate.
///
[InputControl(layout = "Button")]
public int third;
///
/// See
///
/// Callback context for the binding composite. Unity
/// uses this to access the values supplied by part bindings.
/// read from the context.
public override float ReadValue(ref InputBindingCompositeContext context)
{
var value = context.ReadValue(first, out var sourceControl);
if (sourceControl != null)
return value;
value = context.ReadValue(second, out sourceControl);
if (sourceControl != null)
return value;
value = context.ReadValue(third);
return value;
}
///
/// See
///
/// Callback context for the binding composite. Unity
/// uses this to access the values supplied by part bindings.
/// magnitude read from the context.
public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
{
return ReadValue(ref context);
}
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad), Preserve]
#pragma warning disable IDE0051 // Remove unused private members
// ReSharper disable once UnusedMember.Local
static void Initialize()
#pragma warning restore IDE0051
{
// Will execute the static constructor as a side effect.
}
[Preserve]
static ButtonFallbackComposite()
{
InputSystem.InputSystem.RegisterBindingComposite();
}
}
///
/// Base class for a composite that returns a single value computed from an ordered list of bindings.
///
/// Type of value returned by the composite.
///
/// This composite allows for defining multiple binding paths, but unlike a Value action with
/// multiple bindings which uses control magnitude to select the active control, this composite
/// uses an ordered priority list of bindings. If the first input binding is not bound to
/// an input control, it falls back to try the second input binding, and so on.
///
[Preserve]
public abstract class FallbackComposite : InputBindingComposite
where TValue : struct
{
internal struct QuaternionCompositeComparer : IComparer
{
public int Compare(Quaternion x, Quaternion y)
{
if (x == Quaternion.identity)
{
if (y == Quaternion.identity)
return 0;
return -1;
}
return 1;
}
}
}
}