test
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine.InputSystem.Editor;
|
||||
using UnityEngine.UIElements;
|
||||
#endif
|
||||
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
/// <summary>
|
||||
/// Clamps values to the range given by <see cref="min"/> and <see cref="max"/> and re-normalizes the resulting
|
||||
/// value to [0..1].
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This processor is registered (see <see cref="InputSystem.RegisterProcessor{T}"/>) under the name "AxisDeadzone".
|
||||
///
|
||||
/// It acts like a combination of <see cref="ClampProcessor"/> and <see cref="NormalizeProcessor"/>.
|
||||
///
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// </code>
|
||||
/// // Bind to right trigger on gamepad such that the value is clamped and normalized between
|
||||
/// // 0.3 and 0.7.
|
||||
/// new InputAction(binding: "<Gamepad>/rightTrigger", processors: "axisDeadzone(min=0.3,max=0.7)");
|
||||
/// </example>
|
||||
/// </remarks>
|
||||
/// <seealso cref="StickDeadzoneProcessor"/>
|
||||
public class AxisDeadzoneProcessor : InputProcessor<float>
|
||||
{
|
||||
/// <summary>
|
||||
/// Lower bound (inclusive) below which input values get clamped. Corresponds to 0 in the normalized range.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If this is equal to 0 (the default), <see cref="InputSettings.defaultDeadzoneMin"/> is used instead.
|
||||
/// </remarks>
|
||||
public float min;
|
||||
|
||||
/// <summary>
|
||||
/// Upper bound (inclusive) beyond which input values get clamped. Corresponds to 1 in the normalized range.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If this is equal to 0 (the default), <see cref="InputSettings.defaultDeadzoneMax"/> is used instead.
|
||||
/// </remarks>
|
||||
public float max;
|
||||
|
||||
private float minOrDefault => min == default ? InputSystem.settings.defaultDeadzoneMin : min;
|
||||
private float maxOrDefault => max == default ? InputSystem.settings.defaultDeadzoneMax : max;
|
||||
|
||||
/// <summary>
|
||||
/// Normalize <paramref name="value"/> according to <see cref="min"/> and <see cref="max"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Input value.</param>
|
||||
/// <param name="control">Ignored.</param>
|
||||
/// <returns>Normalized value.</returns>
|
||||
public override float Process(float value, InputControl control = null)
|
||||
{
|
||||
var min = minOrDefault;
|
||||
var max = maxOrDefault;
|
||||
|
||||
var absValue = Mathf.Abs(value);
|
||||
if (absValue < min)
|
||||
return 0;
|
||||
if (absValue > max)
|
||||
return Mathf.Sign(value);
|
||||
|
||||
return Mathf.Sign(value) * ((absValue - min) / (max - min));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"AxisDeadzone(min={minOrDefault},max={maxOrDefault})";
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
internal class AxisDeadzoneProcessorEditor : InputParameterEditor<AxisDeadzoneProcessor>
|
||||
{
|
||||
protected override void OnEnable()
|
||||
{
|
||||
m_MinSetting.Initialize("Min",
|
||||
"Value below which input values will be clamped. After clamping, values will be renormalized to [0..1] between min and max.",
|
||||
"Default Deadzone Min",
|
||||
() => target.min, v => target.min = v,
|
||||
() => InputSystem.settings.defaultDeadzoneMin);
|
||||
m_MaxSetting.Initialize("Max",
|
||||
"Value above which input values will be clamped. After clamping, values will be renormalized to [0..1] between min and max.",
|
||||
"Default Deadzone Max",
|
||||
() => target.max, v => target.max = v,
|
||||
() => InputSystem.settings.defaultDeadzoneMax);
|
||||
}
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
|
||||
if (!InputSystem.settings.IsFeatureEnabled(InputFeatureNames.kUseIMGUIEditorForAssets)) return;
|
||||
#endif
|
||||
m_MinSetting.OnGUI();
|
||||
m_MaxSetting.OnGUI();
|
||||
}
|
||||
|
||||
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
|
||||
public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback)
|
||||
{
|
||||
m_MinSetting.OnDrawVisualElements(root, onChangedCallback);
|
||||
m_MaxSetting.OnDrawVisualElements(root, onChangedCallback);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
private CustomOrDefaultSetting m_MinSetting;
|
||||
private CustomOrDefaultSetting m_MaxSetting;
|
||||
}
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 110e42b335c6744e482ada733cbda674
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,55 @@
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
////TODO: move clamping settings into struct and add process function; then embed both here and in AxisControl
|
||||
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
/// <summary>
|
||||
/// Clamp a floating-point input to between <see cref="min"/> and <see cref="max"/>. This is equivalent
|
||||
/// to <c>Mathf.Clamp(value, min, max)</c>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This processor is registered (see <see cref="InputSystem.RegisterProcessor{T}"/>) under the name "clamp" by default.
|
||||
///
|
||||
/// Note that no normalization is performed. If you want to re-normalize the input value after clamping,
|
||||
/// add a <see cref="NormalizeProcessor"/>. Alternatively, add a <see cref="AxisDeadzoneProcessor"/> which
|
||||
/// both clamps and normalizes.
|
||||
///
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// </code>
|
||||
/// // Bind to right trigger on gamepad such that the value never drops below 0.3 and never goes
|
||||
/// // above 0.7.
|
||||
/// new InputAction(binding: "<Gamepad>/rightTrigger", processors: "clamp(min=0.3,max=0.7)");
|
||||
/// </example>
|
||||
/// </remarks>
|
||||
public class ClampProcessor : InputProcessor<float>
|
||||
{
|
||||
/// <summary>
|
||||
/// Minimum value (inclusive!) of the accepted value range.
|
||||
/// </summary>
|
||||
public float min;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum value (inclusive!) of the accepted value range.
|
||||
/// </summary>
|
||||
public float max;
|
||||
|
||||
/// <summary>
|
||||
/// Clamp <paramref name="value"/> to the range of <see cref="min"/> and <see cref="max"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Input value.</param>
|
||||
/// <param name="control">Ignored.</param>
|
||||
/// <returns>Clamped value.</returns>
|
||||
public override float Process(float value, InputControl control)
|
||||
{
|
||||
return Mathf.Clamp(value, min, max);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Clamp(min={min},max={max})";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6887ac562f464a329bc468158dbbf18f
|
||||
timeCreated: 1506740041
|
@@ -0,0 +1,31 @@
|
||||
using System.ComponentModel;
|
||||
using UnityEngine.InputSystem.LowLevel;
|
||||
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
[DesignTimeVisible(false)]
|
||||
internal class CompensateDirectionProcessor : InputProcessor<Vector3>
|
||||
{
|
||||
public override Vector3 Process(Vector3 value, InputControl control)
|
||||
{
|
||||
if (!InputSystem.settings.compensateForScreenOrientation)
|
||||
return value;
|
||||
|
||||
var rotation = Quaternion.identity;
|
||||
switch (InputRuntime.s_Instance.screenOrientation)
|
||||
{
|
||||
case ScreenOrientation.PortraitUpsideDown: rotation = Quaternion.Euler(0, 0, 180); break;
|
||||
case ScreenOrientation.LandscapeLeft: rotation = Quaternion.Euler(0, 0, 90); break;
|
||||
case ScreenOrientation.LandscapeRight: rotation = Quaternion.Euler(0, 0, 270); break;
|
||||
}
|
||||
return rotation * value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "CompensateDirection()";
|
||||
}
|
||||
|
||||
public override CachingPolicy cachingPolicy => CachingPolicy.EvaluateOnEveryRead;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dbce6ac3ce95e4e28af8b2212171619a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,34 @@
|
||||
using System.ComponentModel;
|
||||
using UnityEngine.InputSystem.LowLevel;
|
||||
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
[DesignTimeVisible(false)]
|
||||
internal class CompensateRotationProcessor : InputProcessor<Quaternion>
|
||||
{
|
||||
public override Quaternion Process(Quaternion value, InputControl control)
|
||||
{
|
||||
if (!InputSystem.settings.compensateForScreenOrientation)
|
||||
return value;
|
||||
|
||||
const float kSqrtOfTwo = 1.4142135623731f;
|
||||
var q = Quaternion.identity;
|
||||
|
||||
switch (InputRuntime.s_Instance.screenOrientation)
|
||||
{
|
||||
case ScreenOrientation.PortraitUpsideDown: q = new Quaternion(0.0f, 0.0f, 1.0f /*sin(pi/2)*/, 0.0f /*cos(pi/2)*/); break;
|
||||
case ScreenOrientation.LandscapeLeft: q = new Quaternion(0.0f, 0.0f, kSqrtOfTwo * 0.5f /*sin(pi/4)*/, -kSqrtOfTwo * 0.5f /*cos(pi/4)*/); break;
|
||||
case ScreenOrientation.LandscapeRight: q = new Quaternion(0.0f, 0.0f, -kSqrtOfTwo * 0.5f /*sin(3pi/4)*/, -kSqrtOfTwo * 0.5f /*cos(3pi/4)*/); break;
|
||||
}
|
||||
|
||||
return value * q;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "CompensateRotation()";
|
||||
}
|
||||
|
||||
public override CachingPolicy cachingPolicy => CachingPolicy.EvaluateOnEveryRead;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ef7b744d03d44f2a82c38ac2f25b21f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,56 @@
|
||||
#if UNITY_EDITOR || PACKAGE_DOCS_GENERATION
|
||||
using System.ComponentModel;
|
||||
using UnityEngine.InputSystem.LowLevel;
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
/// <summary>
|
||||
/// If Unity is currently in an <see cref="EditorWindow"/> callback, transforms a 2D coordinate from
|
||||
/// player window space into window space of the current EditorWindow.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This processor is only available in the editor. Also, it only works on devices that
|
||||
/// support the <see cref="QueryEditorWindowCoordinatesCommand"/> request.
|
||||
///
|
||||
/// Outside of <see cref="EditorWindow"/> callbacks, this processor does nothing and just passes through
|
||||
/// the coordinates it receives.
|
||||
/// </remarks>
|
||||
/// <seealso cref="Pointer.position"/>
|
||||
[DesignTimeVisible(false)]
|
||||
public class EditorWindowSpaceProcessor : InputProcessor<Vector2>
|
||||
{
|
||||
/// <summary>
|
||||
/// Transform the given player screen-space coordinate into the coordinate space of the current
|
||||
/// <c>EditorWindow</c>.
|
||||
/// </summary>
|
||||
/// <param name="value">GameView screen space coordinate.</param>
|
||||
/// <param name="control">Ignored.</param>
|
||||
/// <returns>The given coordinate transformed into <c>EditorWindow</c> space.</returns>
|
||||
/// <remarks>
|
||||
/// This method will only succeed if the editor is currently in an <c>EditorWindow</c> callback such
|
||||
/// as <c>OnGUI</c>.
|
||||
/// </remarks>
|
||||
public override Vector2 Process(Vector2 value, InputControl control)
|
||||
{
|
||||
// We go and fire trigger QueryEditorWindowCoordinatesCommand regardless
|
||||
// of whether we are currently in EditorWindow code or not. The expectation
|
||||
// here is that the underlying editor code is in a better position than us
|
||||
// to judge whether the conversion should be performed or not. In native code,
|
||||
// the IOCTL implementations will early out if they detect that the current
|
||||
// EditorWindow is in fact a game view.
|
||||
|
||||
if (Mouse.s_PlatformMouseDevice != null)
|
||||
{
|
||||
var command = QueryEditorWindowCoordinatesCommand.Create(value);
|
||||
// Not all pointer devices implement the editor window position IOCTL,
|
||||
// so we try the global mouse device if available.
|
||||
if (Mouse.s_PlatformMouseDevice.ExecuteCommand(ref command) > 0)
|
||||
return command.inOutCoordinates;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // UNITY_EDITOR
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87ce818774f4c544882b249f32619300
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,37 @@
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
/// <summary>
|
||||
/// An input processor that inverts its input value.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This process is registered (see <see cref="InputSystem.RegisterProcessor{T}"/> as "invert" by default.
|
||||
///
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // Bind to the gamepad's left trigger such that it returns inverted values.
|
||||
/// new InputAction(binding: "<Gamepad>/leftTrigger", processors="invert");
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// </remarks>
|
||||
public class InvertProcessor : InputProcessor<float>
|
||||
{
|
||||
/// <summary>
|
||||
/// Return the inverted value of <paramref name="value"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Input value.</param>
|
||||
/// <param name="control">Ignored.</param>
|
||||
/// <returns>Invert value.</returns>
|
||||
public override float Process(float value, InputControl control)
|
||||
{
|
||||
return value * -1.0f;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return "Invert()";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84e410cdded84dd3971c9dbe94605503
|
||||
timeCreated: 1506740035
|
@@ -0,0 +1,52 @@
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
/// <summary>
|
||||
/// Inverts the <c>x</c> and/or <c>y</c> channel of a <c>Vector2</c>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This process is registered (see <see cref="InputSystem.RegisterProcessor{T}"/> as "invertVector2" by default.
|
||||
///
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // Bind to the left stick on the gamepad such that its Y channel is inverted.
|
||||
/// new InputAction(binding: "<Gamepad>/leftStick", processors="invertVector2(invertY,invertX=false)");
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// </remarks>
|
||||
/// <seealso cref="InvertVector3Processor"/>
|
||||
public class InvertVector2Processor : InputProcessor<Vector2>
|
||||
{
|
||||
/// <summary>
|
||||
/// If true, the <c>x</c> channel of the <c>Vector2</c> input value is inverted. True by default.
|
||||
/// </summary>
|
||||
public bool invertX = true;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the <c>y</c> channel of the <c>Vector2</c> input value is inverted. True by default.
|
||||
/// </summary>
|
||||
public bool invertY = true;
|
||||
|
||||
/// <summary>
|
||||
/// Invert the <c>x</c> and/or <c>y</c> channel of the given <paramref name="value"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Input value.</param>
|
||||
/// <param name="control">Ignored.</param>
|
||||
/// <returns>Vector2 with inverted channels.</returns>
|
||||
public override Vector2 Process(Vector2 value, InputControl control)
|
||||
{
|
||||
if (invertX)
|
||||
value.x *= -1;
|
||||
if (invertY)
|
||||
value.y *= -1;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"InvertVector2(invertX={invertX},invertY={invertY})";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ab0ce1980d384014be67a2d135ed92c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,59 @@
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
/// <summary>
|
||||
/// Inverts the <c>x</c> and/or <c>y</c> and/or <c>z</c> channel of a <c>Vector3</c>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This process is registered (see <see cref="InputSystem.RegisterProcessor{T}"/> as "invertVector3" by default.
|
||||
///
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // Bind to gravity sensor such that its Y value is inverted.
|
||||
/// new InputAction(binding: "<GravitySensor>/gravity", processors="invertVector3(invertX=false,invertY,invertZ=false)");
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// </remarks>
|
||||
/// <seealso cref="InvertVector2Processor"/>
|
||||
public class InvertVector3Processor : InputProcessor<Vector3>
|
||||
{
|
||||
/// <summary>
|
||||
/// If true, the <c>x</c> channel of the <c>Vector3</c> input value is inverted. True by default.
|
||||
/// </summary>
|
||||
public bool invertX = true;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the <c>y</c> channel of the <c>Vector3</c> input value is inverted. True by default.
|
||||
/// </summary>
|
||||
public bool invertY = true;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the <c>z</c> channel of the <c>Vector3</c> input value is inverted. True by default.
|
||||
/// </summary>
|
||||
public bool invertZ = true;
|
||||
|
||||
/// <summary>
|
||||
/// Return the given vector with the respective channels being inverted.
|
||||
/// </summary>
|
||||
/// <param name="value">Input value.</param>
|
||||
/// <param name="control">Ignored.</param>
|
||||
/// <returns>Vector with channels inverted according to <see cref="invertX"/>, <see cref="invertY"/>, and <see cref="invertZ"/>.</returns>
|
||||
public override Vector3 Process(Vector3 value, InputControl control)
|
||||
{
|
||||
if (invertX)
|
||||
value.x *= -1;
|
||||
if (invertY)
|
||||
value.y *= -1;
|
||||
if (invertZ)
|
||||
value.z *= -1;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"InvertVector3(invertX={invertX},invertY={invertY},invertZ={invertZ})";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7938861606c2845d19cf2e8a683ddba3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,121 @@
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
////REVIEW: handle values dropping below min and above max?
|
||||
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
/// <summary>
|
||||
/// Normalizes input values in the range <see cref="min"/> and <see cref="max"/> to
|
||||
/// unsigned normalized form [0..1] if <see cref="zero"/> is placed at (or below) <see cref="min"/>
|
||||
/// or to signed normalized form [-1..1] if <see cref="zero"/> is placed in-between
|
||||
/// <see cref="min"/> and <see cref="max"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This processor is registered (see <see cref="InputSystem.RegisterProcessor{T}"/>) under the name "normalize".
|
||||
///
|
||||
/// Note that this processor does not clamp the incoming value to <see cref="min"/> and <see cref="max"/>.
|
||||
/// To achieve this, either add a <see cref="ClampProcessor"/> or use <see cref="AxisDeadzoneProcessor"/>
|
||||
/// which combines clamping and normalizing.
|
||||
///
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// </code>
|
||||
/// // Bind to right trigger on gamepad such that the value values below 0.3 and above 0.7 get normalized
|
||||
/// // to values between [0..1].
|
||||
/// new InputAction(binding: "<Gamepad>/rightTrigger", processors: "normalize(min=0.3,max=0.7)");
|
||||
/// </example>
|
||||
/// </remarks>
|
||||
/// <seealso cref="NormalizeVector2Processor"/>
|
||||
/// <seealso cref="NormalizeVector3Processor"/>
|
||||
public class NormalizeProcessor : InputProcessor<float>
|
||||
{
|
||||
/// <summary>
|
||||
/// Input value (inclusive) that corresponds to 0 or -1 (depending on <see cref="zero"/>), the lower bound.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the input value drops below min, the result is undefined.
|
||||
/// </remarks>
|
||||
public float min;
|
||||
|
||||
/// <summary>
|
||||
/// Input value (inclusive) that corresponds to 1, the upper bound.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the input value goes beyond max, the result is undefined.
|
||||
/// </remarks>
|
||||
public float max;
|
||||
|
||||
/// <summary>
|
||||
/// Input value that corresponds to 0. If this is placed at or below <see cref="min"/>, the resulting normalization
|
||||
/// returns a [0..1] value. If this is placed in-between <see cref="min"/> and <see cref="max"/>, the resulting
|
||||
/// normalization returns a [-1..1] value.
|
||||
/// </summary>
|
||||
public float zero;
|
||||
|
||||
/// <summary>
|
||||
/// Normalize <paramref name="value"/> with respect to <see cref="min"/> and <see cref="max"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Input value.</param>
|
||||
/// <param name="control">Ignored.</param>
|
||||
/// <returns>Normalized value.</returns>
|
||||
public override float Process(float value, InputControl control)
|
||||
{
|
||||
return Normalize(value, min, max, zero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalize <paramref name="value"/> with respect to <paramref name="min"/> and <paramref name="max"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Input value.</param>
|
||||
/// <param name="min">Lower bound. See <see cref="min"/>.</param>
|
||||
/// <param name="max">Upper bound. See <see cref="max"/>.</param>
|
||||
/// <param name="zero">Zero point. See <see cref="zero"/>.</param>
|
||||
/// <returns>Normalized value.</returns>
|
||||
/// <remarks>
|
||||
/// This method performs the same function as <see cref="Process"/>.
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // Normalize 2 against a [1..5] range. Returns 0.25.
|
||||
/// NormalizeProcessor.Normalize(2, 1, 5, 1)
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// </remarks>
|
||||
public static float Normalize(float value, float min, float max, float zero)
|
||||
{
|
||||
if (zero < min)
|
||||
zero = min;
|
||||
// Prevent NaN/Inf from dividing 0 by something.
|
||||
if (Mathf.Approximately(value, min))
|
||||
{
|
||||
if (min < zero)
|
||||
return -1f;
|
||||
return 0f;
|
||||
}
|
||||
var percentage = (value - min) / (max - min);
|
||||
if (min < zero)
|
||||
return 2 * percentage - 1;
|
||||
return percentage;
|
||||
}
|
||||
|
||||
internal static float Denormalize(float value, float min, float max, float zero)
|
||||
{
|
||||
if (zero < min)
|
||||
zero = min;
|
||||
|
||||
if (min < zero)
|
||||
{
|
||||
if (value < 0)
|
||||
return min + (zero - min) * (value * -1f);
|
||||
return zero + (max - zero) * value;
|
||||
}
|
||||
|
||||
return min + (max - min) * value;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Normalize(min={min},max={max},zero={zero})";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94995588a5664878be30498a8ace6ba2
|
||||
timeCreated: 1506740059
|
@@ -0,0 +1,31 @@
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
/// <summary>
|
||||
/// Normalizes a <c>Vector2</c> input value.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This processor is registered (see <see cref="InputSystem.RegisterProcessor{T}"/>) under the name "normalizeVector2".
|
||||
/// </remarks>
|
||||
/// <seealso cref="NormalizeVector3Processor"/>
|
||||
public class NormalizeVector2Processor : InputProcessor<Vector2>
|
||||
{
|
||||
/// <summary>
|
||||
/// Normalize <paramref name="value"/>. Performs the equivalent of <c>value.normalized</c>.
|
||||
/// </summary>
|
||||
/// <param name="value">Input vector.</param>
|
||||
/// <param name="control">Ignored.</param>
|
||||
/// <returns>Normalized vector.</returns>
|
||||
public override Vector2 Process(Vector2 value, InputControl control)
|
||||
{
|
||||
return value.normalized;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return "NormalizeVector2()";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ae082cf4f6634e9d8cdd8526dd816a3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,31 @@
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
/// <summary>
|
||||
/// Normalizes a <c>Vector3</c> input value.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This processor is registered (see <see cref="InputSystem.RegisterProcessor{T}"/>) under the name "normalizeVector3".
|
||||
/// </remarks>
|
||||
/// <seealso cref="NormalizeVector2Processor"/>
|
||||
public class NormalizeVector3Processor : InputProcessor<Vector3>
|
||||
{
|
||||
/// <summary>
|
||||
/// Normalize <paramref name="value"/>. Performs the equivalent of <c>value.normalized</c>.
|
||||
/// </summary>
|
||||
/// <param name="value">Input vector.</param>
|
||||
/// <param name="control">Ignored.</param>
|
||||
/// <returns>Normalized vector.</returns>
|
||||
public override Vector3 Process(Vector3 value, InputControl control)
|
||||
{
|
||||
return value.normalized;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return "NormalizeVector3()";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b78cdd0ba4454fd69b2be04e825d921
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,45 @@
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
/// <summary>
|
||||
/// Scale a float value by a constant factor.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This processor is registered (see <see cref="InputSystem.RegisterProcessor{T}"/>) under the name "scale".
|
||||
///
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// </code>
|
||||
/// // Bind to left trigger on the gamepad such that its values are scaled by a factor of 2.
|
||||
/// new InputAction(binding: "<Gamepad>/leftTrigger", processors: "scale(factor=2)");
|
||||
/// </example>
|
||||
/// </remarks>
|
||||
/// <seealso cref="ScaleVector2Processor"/>
|
||||
/// <seealso cref="ScaleVector3Processor"/>
|
||||
public class ScaleProcessor : InputProcessor<float>
|
||||
{
|
||||
/// <summary>
|
||||
/// Scale factor to apply to incoming input values. Defaults to 1 (no scaling).
|
||||
/// </summary>
|
||||
[Tooltip("Scale factor to multiply incoming float values by.")]
|
||||
public float factor = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Scale the given <paramref name="value"/> by <see cref="factor"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Input value.</param>
|
||||
/// <param name="control">Ignored.</param>
|
||||
/// <returns>Scaled value.</returns>
|
||||
public override float Process(float value, InputControl control)
|
||||
{
|
||||
return value * factor;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Scale(factor={factor})";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98590516d066443e58df0deff4a95b21
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,49 @@
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
/// <summary>
|
||||
/// Scale the components of a <see cref="Vector2"/> by constant factors.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This processor is registered (see <see cref="InputSystem.RegisterProcessor{T}"/>) under the name "scaleVector2".
|
||||
///
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // Double the length of the vector produced by leftStick on gamepad.
|
||||
/// myAction.AddBinding("<Gamepad>/leftStick").WithProcessor("scaleVector2(x=2,y=2)");
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// </remarks>
|
||||
/// <seealso cref="ScaleProcessor"/>
|
||||
/// <seealso cref="ScaleVector3Processor"/>
|
||||
public class ScaleVector2Processor : InputProcessor<Vector2>
|
||||
{
|
||||
/// <summary>
|
||||
/// Scale factor to apply to the vector's <c>x</c> axis. Defaults to 1.
|
||||
/// </summary>
|
||||
[Tooltip("Scale factor to multiply the incoming Vector2's X component by.")]
|
||||
public float x = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Scale factor to apply to the vector's <c>y</c> axis. Defaults to 1.
|
||||
/// </summary>
|
||||
[Tooltip("Scale factor to multiply the incoming Vector2's Y component by.")]
|
||||
public float y = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Return <paramref name="value"/> scaled by <see cref="x"/> and <see cref="y"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Input value.</param>
|
||||
/// <param name="control">Ignored.</param>
|
||||
/// <returns>Scaled vector.</returns>
|
||||
public override Vector2 Process(Vector2 value, InputControl control)
|
||||
{
|
||||
return new Vector2(value.x * x, value.y * y);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"ScaleVector2(x={x},y={y})";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96bf34fe183cd4ce986db61a6639cd5b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,57 @@
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
/// <summary>
|
||||
/// Scale the components of a <see cref="Vector3"/> by constant factors.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This processor is registered (see <see cref="InputSystem.RegisterProcessor{T}"/>) under the name "scaleVector3".
|
||||
///
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // Double the magnitude of gravity values read from a gravity sensor.
|
||||
/// myAction.AddBinding("<GravitySensor>/gravity").WithProcessor("scaleVector3(x=2,y=2,z=2)");
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// </remarks>
|
||||
/// <seealso cref="ScaleProcessor"/>
|
||||
/// <seealso cref="ScaleVector2Processor"/>
|
||||
public class ScaleVector3Processor : InputProcessor<Vector3>
|
||||
{
|
||||
/// <summary>
|
||||
/// Scale factor to apply to the vector's <c>x</c> axis. Defaults to 1.
|
||||
/// </summary>
|
||||
[Tooltip("Scale factor to multiply the incoming Vector3's X component by.")]
|
||||
public float x = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Scale factor to apply to the vector's <c>y</c> axis. Defaults to 1.
|
||||
/// </summary>
|
||||
[Tooltip("Scale factor to multiply the incoming Vector3's Y component by.")]
|
||||
public float y = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Scale factor to apply to the vector's <c>z</c> axis. Defaults to 1.
|
||||
/// </summary>
|
||||
[Tooltip("Scale factor to multiply the incoming Vector3's Z component by.")]
|
||||
public float z = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Return <paramref name="value"/> scaled by <see cref="x"/>, <see cref="y"/>, and <see cref="z"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Input value.</param>
|
||||
/// <param name="control">Ignored.</param>
|
||||
/// <returns>Scaled vector.</returns>
|
||||
public override Vector3 Process(Vector3 value, InputControl control)
|
||||
{
|
||||
return new Vector3(value.x * x, value.y * y, value.z * z);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"ScaleVector3(x={x},y={y},z={z})";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 681942113a3d6460a90af134a86edb78
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine.InputSystem.Editor;
|
||||
using UnityEngine.UIElements;
|
||||
#endif
|
||||
|
||||
////REVIEW: rename to RadialDeadzone
|
||||
|
||||
////TODO: add different deadzone shapes and/or option to min/max X and Y separately
|
||||
|
||||
namespace UnityEngine.InputSystem.Processors
|
||||
{
|
||||
/// <summary>
|
||||
/// Processes a Vector2 to apply deadzoning according to the magnitude of the vector (rather
|
||||
/// than just clamping individual axes). Normalizes to the min/max range.
|
||||
/// </summary>
|
||||
/// <seealso cref="AxisDeadzoneProcessor"/>
|
||||
public class StickDeadzoneProcessor : InputProcessor<Vector2>
|
||||
{
|
||||
/// <summary>
|
||||
/// Value at which the lower bound deadzone starts.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Values in the input at or below min will get dropped and values
|
||||
/// will be scaled to the range between min and max.
|
||||
/// </remarks>
|
||||
public float min;
|
||||
public float max;
|
||||
|
||||
private float minOrDefault => min == default ? InputSystem.settings.defaultDeadzoneMin : min;
|
||||
private float maxOrDefault => max == default ? InputSystem.settings.defaultDeadzoneMax : max;
|
||||
|
||||
public override Vector2 Process(Vector2 value, InputControl control = null)
|
||||
{
|
||||
var magnitude = value.magnitude;
|
||||
var newMagnitude = GetDeadZoneAdjustedValue(magnitude);
|
||||
if (newMagnitude == 0)
|
||||
value = Vector2.zero;
|
||||
else
|
||||
value *= newMagnitude / magnitude;
|
||||
return value;
|
||||
}
|
||||
|
||||
private float GetDeadZoneAdjustedValue(float value)
|
||||
{
|
||||
var min = minOrDefault;
|
||||
var max = maxOrDefault;
|
||||
|
||||
var absValue = Mathf.Abs(value);
|
||||
if (absValue < min)
|
||||
return 0;
|
||||
if (absValue > max)
|
||||
return Mathf.Sign(value);
|
||||
|
||||
return Mathf.Sign(value) * ((absValue - min) / (max - min));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"StickDeadzone(min={minOrDefault},max={maxOrDefault})";
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
internal class StickDeadzoneProcessorEditor : InputParameterEditor<StickDeadzoneProcessor>
|
||||
{
|
||||
protected override void OnEnable()
|
||||
{
|
||||
m_MinSetting.Initialize("Min",
|
||||
"Vector length below which input values will be clamped. After clamping, vector lengths will be renormalized to [0..1] between min and max.",
|
||||
"Default Deadzone Min",
|
||||
() => target.min, v => target.min = v,
|
||||
() => InputSystem.settings.defaultDeadzoneMin);
|
||||
m_MaxSetting.Initialize("Max",
|
||||
"Vector length above which input values will be clamped. After clamping, vector lengths will be renormalized to [0..1] between min and max.",
|
||||
"Default Deadzone Max",
|
||||
() => target.max, v => target.max = v,
|
||||
() => InputSystem.settings.defaultDeadzoneMax);
|
||||
}
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
|
||||
if (!InputSystem.settings.IsFeatureEnabled(InputFeatureNames.kUseIMGUIEditorForAssets)) return;
|
||||
#endif
|
||||
m_MinSetting.OnGUI();
|
||||
m_MaxSetting.OnGUI();
|
||||
}
|
||||
|
||||
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
|
||||
public override void OnDrawVisualElements(VisualElement root, Action onChangedCallback)
|
||||
{
|
||||
m_MinSetting.OnDrawVisualElements(root, onChangedCallback);
|
||||
m_MaxSetting.OnDrawVisualElements(root, onChangedCallback);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
private CustomOrDefaultSetting m_MinSetting;
|
||||
private CustomOrDefaultSetting m_MaxSetting;
|
||||
}
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a327bafe91572467f834d0435da166fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user