예제 #1
0
        public unsafe Vector2 ReadValue(ref InputBindingCompositeContext context)
        {
            Vector2 result;

            ReadValue(ref context, &result, sizeof(Vector2));
            return(result);
        }
예제 #2
0
        ////TODO: add parameters to control ramp up&down

        /// <inheritdoc />
        public override float ReadValue(ref InputBindingCompositeContext context)
        {
            var negativeValue = Mathf.Abs(context.ReadValue <float>(negative));
            var positiveValue = Mathf.Abs(context.ReadValue <float>(positive));

            var negativeIsActuated = negativeValue > Mathf.Epsilon;
            var positiveIsActuated = positiveValue > Mathf.Epsilon;

            if (negativeIsActuated == positiveIsActuated)
            {
                switch (whichSideWins)
                {
                case WhichSideWins.Negative:
                    positiveIsActuated = false;
                    break;

                case WhichSideWins.Positive:
                    negativeIsActuated = false;
                    break;

                case WhichSideWins.Neither:
                    return(midPoint);
                }
            }

            var mid = midPoint;

            if (negativeIsActuated)
            {
                return(mid - (mid - minValue) * negativeValue);
            }

            return(mid + (maxValue - mid) * positiveValue);
        }
예제 #3
0
    public override myCompositData ReadValue(ref InputBindingCompositeContext context)
    {
        var press      = context.ReadValueAsButton(this.press);
        var pressCount = context.ReadValue <int>(this.pressCount);
        var position   = context.ReadValue <Vector2, Vector2MagnitudeComparer>(this.position);
        var delta      = context.ReadValue <Vector2, Vector2MagnitudeComparer>(this.delta);
        var radius     = context.ReadValue <Vector2, Vector2MagnitudeComparer>(this.radius);

        var tap = context.ReadValueAsButton(this.tap);
        //var phase = context.ReadValue<UnityEngine.InputSystem.TouchPhase>(this.phase);
        var startPosition = context.ReadValue <Vector2, Vector2MagnitudeComparer>(this.startPosition);
        var startTime     = context.ReadValue <double>(this.startTime);

        var scroll = context.ReadValue <Vector2, Vector2MagnitudeComparer>(this.scroll);

        return(new myCompositData()
        {
            Press = press,
            PressCount = pressCount,
            Position = position,
            Delta = delta,
            Radius = radius,

            Tap = tap,
            StartPosition = startPosition,
            StartTime = startTime,

            Scroll = scroll
        });
    }
 public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
 {
     if (context.ReadValueAsButton(modifier))
     {
         return(context.EvaluateMagnitude(binding));
     }
     return(default);
예제 #5
0
        /// <inheritdoc />
        public override Vector2 ReadValue(ref InputBindingCompositeContext context)
        {
            var mode = this.mode;

            if (mode == Mode.Analog)
            {
                var upValue    = context.ReadValue <float>(up);
                var downValue  = context.ReadValue <float>(down);
                var leftValue  = context.ReadValue <float>(left);
                var rightValue = context.ReadValue <float>(right);

                return(DpadControl.MakeDpadVector(upValue, downValue, leftValue, rightValue));
            }

            var upIsPressed    = context.ReadValueAsButton(up);
            var downIsPressed  = context.ReadValueAsButton(down);
            var leftIsPressed  = context.ReadValueAsButton(left);
            var rightIsPressed = context.ReadValueAsButton(right);

            // Legacy. We need to reference the obsolete member here so temporarily
            // turn of the warning.
            #pragma warning disable CS0618
            if (!normalize) // Was on by default.
            {
                mode = Mode.Digital;
            }
            #pragma warning restore CS0618

            return(DpadControl.MakeDpadVector(upIsPressed, downIsPressed, leftIsPressed, rightIsPressed, mode == Mode.DigitalNormalized));
        }
예제 #6
0
        /// <inheritdoc/>
        public override Vector3 ReadValue(ref InputBindingCompositeContext context)
        {
            if (mode == Mode.Analog)
            {
                var upValue       = context.ReadValue <float>(up);
                var downValue     = context.ReadValue <float>(down);
                var leftValue     = context.ReadValue <float>(left);
                var rightValue    = context.ReadValue <float>(right);
                var forwardValue  = context.ReadValue <float>(forward);
                var backwardValue = context.ReadValue <float>(backward);

                return(new Vector3(rightValue - leftValue, upValue - downValue, forwardValue - backwardValue));
            }
            else
            {
                var upValue       = context.ReadValueAsButton(up) ? 1f : 0f;
                var downValue     = context.ReadValueAsButton(down) ? -1f : 0f;
                var leftValue     = context.ReadValueAsButton(left) ? -1f : 0f;
                var rightValue    = context.ReadValueAsButton(right) ? 1f : 0f;
                var forwardValue  = context.ReadValueAsButton(forward) ? 1f : 0f;
                var backwardValue = context.ReadValueAsButton(backward) ? -1f : 0f;

                var vector = new Vector3(leftValue + rightValue, upValue + downValue, forwardValue + backwardValue);

                if (mode == Mode.DigitalNormalized)
                {
                    vector = vector.normalized;
                }

                return(vector);
            }
        }
예제 #7
0
        ////TODO: add parameters to control ramp up&down

        /// <inheritdoc />
        public override float ReadValue(ref InputBindingCompositeContext context)
        {
            var negativeValue = context.ReadValue <float>(negative);
            var positiveValue = context.ReadValue <float>(positive);

            ////TODO: take partial actuation into account (e.g. amount of actuation of gamepad trigger should result in partial actuation of axis)
            ////REVIEW: should this respect press points?

            var negativeIsPressed = negativeValue > 0;
            var positiveIsPressed = positiveValue > 0;

            if (negativeIsPressed == positiveIsPressed)
            {
                switch (whichSideWins)
                {
                case WhichSideWins.Negative:
                    return(-negativeValue);

                case WhichSideWins.Positive:
                    return(positiveValue);

                case WhichSideWins.Neither:
                    return(midPoint);
                }
            }

            if (negativeIsPressed)
            {
                return(-negativeValue);
            }

            return(positiveValue);
        }
예제 #8
0
        public unsafe void ReadValue(ref InputBindingCompositeContext context, void *buffer, int bufferSize)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (bufferSize < sizeof(float))
            {
                throw new ArgumentException("bufferSize < sizeof(float)", "bufferSize");
            }

            var negativeIsPressed = negative.isPressed;
            var positiveIsPressed = positive.isPressed;

            float result;

            if (negativeIsPressed && positiveIsPressed)
            {
                result = 0f;
            }
            else if (negativeIsPressed)
            {
                result = -1f;
            }
            else
            {
                result = 1f;
            }

            *((float *)buffer) = result;
        }
예제 #9
0
        public unsafe float ReadValue(ref InputBindingCompositeContext context)
        {
            float result;

            ReadValue(ref context, &result, sizeof(float));
            return(result);
        }
예제 #10
0
        ////TODO: add parameters to control ramp up&down

        /// <inheritdoc />
        public override float ReadValue(ref InputBindingCompositeContext context)
        {
            var negativeValue = context.ReadValue <float>(negative);
            var positiveValue = context.ReadValue <float>(positive);

            var negativeIsPressed = negativeValue > 0;
            var positiveIsPressed = positiveValue > 0;

            if (negativeIsPressed == positiveIsPressed)
            {
                switch (whichSideWins)
                {
                case WhichSideWins.Negative:
                    return(-negativeValue);

                case WhichSideWins.Positive:
                    return(positiveValue);

                case WhichSideWins.Neither:
                    return(0);
                }
            }

            if (negativeIsPressed)
            {
                return(-negativeValue);
            }

            return(positiveValue);
        }
예제 #11
0
        public Vector2 ReadValue(ref InputBindingCompositeContext context)
        {
            ////TODO: unify code path with DpadControl.ReadRawValueFrom()
            var upIsPressed    = up.isPressed;
            var downIsPressed  = down.isPressed;
            var leftIsPressed  = left.isPressed;
            var rightIsPressed = right.isPressed;

            var upValue    = upIsPressed ? 1.0f : 0.0f;
            var downValue  = downIsPressed ? -1.0f : 0.0f;
            var leftValue  = leftIsPressed ? -1.0f : 0.0f;
            var rightValue = rightIsPressed ? 1.0f : 0.0f;

            var result = new Vector2(leftValue + rightValue, upValue + downValue);

            // If press is diagonal, adjust coordinates to produce vector of length 1.
            // pow(0.707107) is roughly 0.5 so sqrt(pow(0.707107)+pow(0.707107)) is ~1.
            const float diagonal = 0.707107f;

            if (result.x != 0 && result.y != 0)
            {
                return(new Vector2(result.x * diagonal, result.y * diagonal));
            }

            return(result);
        }
예제 #12
0
 public override Vector2 ReadValue(ref InputBindingCompositeContext context)
 {
     if (context.ReadValueAsButton(MouseButton))
     {
         return(context.ReadValue <Vector2, Vector2MagnitudeComparer>(MouseVector)); //hack
     }
     return(default);
예제 #13
0
        ////TODO: add parameters to control ramp up&down

        /// <inheritdoc />
        public override float ReadValue(ref InputBindingCompositeContext context)
        {
            var negativeMagnitude = context.EvaluateMagnitude(negative);
            var positiveMagnitude = context.EvaluateMagnitude(positive);

            var negativeIsPressed = negativeMagnitude > 0;
            var positiveIsPressed = positiveMagnitude > 0;

            if (negativeIsPressed == positiveIsPressed)
            {
                switch (whichSideWins)
                {
                case WhichSideWins.Negative:
                    positiveIsPressed = false;
                    break;

                case WhichSideWins.Positive:
                    negativeIsPressed = false;
                    break;

                case WhichSideWins.Neither:
                    return(midPoint);
                }
            }

            var mid = midPoint;

            if (negativeIsPressed)
            {
                return(mid - (mid - minValue) * negativeMagnitude);
            }

            return(mid + (maxValue - mid) * positiveMagnitude);
        }
예제 #14
0
        public unsafe void ReadValue(ref InputBindingCompositeContext context, void *buffer, int bufferSize)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (bufferSize < sizeof(Vector2))
            {
                throw new ArgumentException("bufferSize < sizeof(Vector2)", "bufferSize");
            }

            var upValue    = context.ReadValue <float>(up);
            var downValue  = context.ReadValue <float>(down);
            var leftValue  = context.ReadValue <float>(left);
            var rightValue = context.ReadValue <float>(right);

            var upIsPressed    = upValue > 0;
            var downIsPressed  = downValue > 0;
            var leftIsPressed  = leftValue > 0;
            var rightIsPressed = rightValue > 0;

            var result =
                DpadControl.MakeDpadVector(upIsPressed, downIsPressed, leftIsPressed, rightIsPressed, normalize);

            *(Vector2 *)buffer = result;
        }
 public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
 {
     if (ModifiersArePressed(ref context))
     {
         return(context.EvaluateMagnitude(binding));
     }
     return(default);
예제 #16
0
        }                      // Trigger static constructor.

        public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
        {
            var modifierCurrentlyActive = context.ReadValueAsButton(Trigger);

            if (modifierActive && !modifierCurrentlyActive)
            {
                modifierActive = false;
            }
            else if (!modifierActive && modifierCurrentlyActive)
            {
                modifierActive = true;
                totalDelta     = Vector2.zero;
            }

            if (modifierActive)
            {
                var val = ReadValue(ref context);
                if (val.x != 0 || val.y != 0)
                {
                    return(1);
                }
            }

            return(0);
        }
예제 #17
0
 public override Vector2 ReadValue(ref InputBindingCompositeContext context)
 {
     if (context.ReadValueAsButton(modifier))
     {
         return(context.ReadValue <Vector2, Vector2MagnitudeComparer>(vector2));
     }
     return(default);
예제 #18
0
        /// <summary>
        /// Return the value of the <see cref="button"/> part while both <see cref="modifier1"/> and <see cref="modifier2"/>
        /// are pressed. Otherwise return 0.
        /// </summary>
        /// <param name="context">Evaluation context passed in from the input system.</param>
        /// <returns>The current value of the composite.</returns>
        public override float ReadValue(ref InputBindingCompositeContext context)
        {
            if (context.ReadValueAsButton(modifier1) && context.ReadValueAsButton(modifier2))
            {
                return(context.ReadValue <float>(button));
            }

            return(default);
        /// <summary>
        /// Return the value of the <see cref="button"/> part if <see cref="modifier"/> is pressed. Otherwise
        /// return 0.
        /// </summary>
        /// <param name="context">Evaluation context passed in from the input system.</param>
        /// <returns>The current value of the composite.</returns>
        public override float ReadValue(ref InputBindingCompositeContext context)
        {
            if (ModifierIsPressed(ref context))
            {
                return(context.ReadValue <float>(button));
            }

            return(default);
예제 #20
0
        public override Vector2 ReadValue(ref InputBindingCompositeContext context)
        {
            var b = context.ReadValueAsButton(Button);
            var x = context.ReadValue <float>(Axis1);
            var y = context.ReadValue <float>(Axis2);
            var v = new Vector2(x, y);

            return(b && v.magnitude > 0.0f ? v : default);
예제 #21
0
        /// <inheritdoc />
        public override Vector2 ReadValue(ref InputBindingCompositeContext context)
        {
            var upIsPressed    = context.ReadValueAsButton(up);
            var downIsPressed  = context.ReadValueAsButton(down);
            var leftIsPressed  = context.ReadValueAsButton(left);
            var rightIsPressed = context.ReadValueAsButton(right);

            return(DpadControl.MakeDpadVector(upIsPressed, downIsPressed, leftIsPressed, rightIsPressed, normalize));
        }
        public override Vector2 ReadValue(ref InputBindingCompositeContext context)
        {
            Vector2 splitAxisValue = new Vector2 {
                x = context.ReadValue <float, HighestMagnitudeFloatComparer>(axisX), y = context.ReadValue <float, HighestMagnitudeFloatComparer>(axisY)
            };
            Vector2 stickValue = context.ReadValue <Vector2, Vector2MagnitudeComparer>(axes);
            Vector2MagnitudeComparer comparer = default;
            Vector2 value = comparer.Compare(splitAxisValue, stickValue) > 0 ? splitAxisValue : stickValue;

            return(context.ReadValue <float, LowestMagnitudeFloatComparer>(modifier) != 0f ? value : default);
예제 #23
0
        public override PointerInput ReadValue(ref InputBindingCompositeContext context)
        {
            var contact   = context.ReadValueAsButton(this.contact);
            var pointerId = context.ReadValue <int>(inputId);
            var position  = context.ReadValue <Vector2, Vector2MagnitudeComparer>(this.position);

            return(new PointerInput
            {
                Contact = contact,
                InputId = pointerId,
                Position = position,
            });
        }
예제 #24
0
        /// <inheritdoc />
        public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
        {
            var value = ReadValue(ref context);

            if (value < midPoint)
            {
                value = Mathf.Abs(value - midPoint);
                return(NormalizeProcessor.Normalize(value, 0, Mathf.Abs(minValue), 0));
            }

            value = Mathf.Abs(value - midPoint);
            return(NormalizeProcessor.Normalize(value, 0, Mathf.Abs(maxValue), 0));
        }
예제 #25
0
        public override Vector2 ReadValue(ref InputBindingCompositeContext context)
        {
            var upValue    = context.ReadValue <float>(up);
            var downValue  = context.ReadValue <float>(down);
            var leftValue  = context.ReadValue <float>(left);
            var rightValue = context.ReadValue <float>(right);

            var upIsPressed    = upValue > 0;
            var downIsPressed  = downValue > 0;
            var leftIsPressed  = leftValue > 0;
            var rightIsPressed = rightValue > 0;

            return(DpadControl.MakeDpadVector(upIsPressed, downIsPressed, leftIsPressed, rightIsPressed, normalize));
        }
예제 #26
0
    public override MouseDragCompositeResult ReadValue(ref InputBindingCompositeContext context)
    {
        if (context.ReadValueAsButton(modifier))
        {
            var newDelta    = context.ReadValue <Vector2, Vector2MagnitudeComparer>(this.delta, comparer);
            var newPosition = context.ReadValue <Vector2, Vector2MagnitudeComparer>(this.position, comparer);

            return(new MouseDragCompositeResult
            {
                delta = newDelta,
                position = newPosition,
            });
        }
        return(default);
예제 #27
0
        // Parameters.
        ////TODO: add parameters to control ramp up&down

        public float ReadValue(ref InputBindingCompositeContext context)
        {
            var negativeIsPressed = negative.isPressed;
            var positiveIsPressed = positive.isPressed;

            if (negativeIsPressed && positiveIsPressed)
            {
                return(0f);
            }
            if (negativeIsPressed)
            {
                return(-1f);
            }
            return(1f);
        }
예제 #28
0
        /// <inheritdoc />
        public override Quaternion ReadValue(ref InputBindingCompositeContext context)
        {
            var value = context.ReadValue <Quaternion, QuaternionCompositeComparer>(first, out var sourceControl);

            if (sourceControl != null)
            {
                return(value);
            }

            value = context.ReadValue <Quaternion, QuaternionCompositeComparer>(second, out sourceControl);
            if (sourceControl != null)
            {
                return(value);
            }

            value = context.ReadValue <Quaternion, QuaternionCompositeComparer>(third);
            return(value);
        }
예제 #29
0
        /// <inheritdoc />
        public override Vector3 ReadValue(ref InputBindingCompositeContext context)
        {
            var value = context.ReadValue <Vector3, Vector3MagnitudeComparer>(first, out var sourceControl);

            if (sourceControl != null)
            {
                return(value);
            }

            value = context.ReadValue <Vector3, Vector3MagnitudeComparer>(second, out sourceControl);
            if (sourceControl != null)
            {
                return(value);
            }

            value = context.ReadValue <Vector3, Vector3MagnitudeComparer>(third);
            return(value);
        }
예제 #30
0
    // Ok, so now we have all the configuration in place. The final piece we
    // need is the actual logic that reads input from "multiplier" and "stick"
    // and computes a final input value.
    //
    // We can do that by defining a ReadValue method which is the actual workhorse
    // for our composite.
    public override Vector2 ReadValue(ref InputBindingCompositeContext context)
    {
        // We read input from the parts we have by simply
        // supplying the part IDs that the input system has set up
        // for us to ReadValue.
        //
        // NOTE: Vector2 is a less straightforward than primitive value types
        //       like int and float. If there are multiple controls bound to the
        //       "stick" part, we need to tell the input system which one to pick.
        //       We do so by giving it an IComparer. In this case, we choose
        //       Vector2MagnitudeComparer to return the Vector2 with the greatest
        //       length.
        var stickValue      = context.ReadValue <Vector2, Vector2MagnitudeComparer>(stick);
        var multiplierValue = context.ReadValue <float>(multiplier);

        // The rest is simple. We just scale the vector we read by the
        // multiple from the axis and apply our scale factor.
        return(stickValue * (multiplierValue * scaleFactor));
    }