예제 #1
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 negativeValue = context.ReadValue <float>(negative);
            var positiveValue = context.ReadValue <float>(positive);

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

            float result;

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

            *((float *)buffer) = result;
        }
예제 #2
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));
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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;
        }
예제 #6
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);
        }
예제 #7
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);
        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);
예제 #9
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,
            });
        }
예제 #10
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);
예제 #11
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));
        }
예제 #12
0
 public override Vector2 ReadValue(ref InputBindingCompositeContext context)
 {
     if (context.ReadValueAsButton(MouseButton))
     {
         return(context.ReadValue <Vector2, Vector2MagnitudeComparer>(MouseVector)); //hack
     }
     return(default);
예제 #13
0
 public override Vector2 ReadValue(ref InputBindingCompositeContext context)
 {
     if (context.ReadValueAsButton(modifier))
     {
         return(context.ReadValue <Vector2, Vector2MagnitudeComparer>(vector2));
     }
     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);
예제 #15
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);
예제 #16
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
        });
    }
예제 #17
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);
        }
예제 #18
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);
        }
예제 #19
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));
    }
        public override Vector2 ReadValue(ref InputBindingCompositeContext context)
        {
            var mouse = context.ReadValue <Vector2, CustomVector2Comparer>(MouseInput, comparer);
            var r0    = context.ReadValue <float>(Rotate0);
            var r90   = context.ReadValue <float>(Rotate90);
            var r180  = context.ReadValue <float>(Rotate180);
            var r270  = context.ReadValue <float>(Rotate270);

            if (r90 != 0 && r180 != 0)
            {
                r90  = 0;
                r180 = 0;
            }
            if (r90 != 0)
            {
                if (r180 != 0 || r0 != 0)
                {
                    mouse = mouse.Rotate(45);
                }
                else
                {
                    mouse = mouse.Rotate(90);
                }
            }
            if (r270 != 0)
            {
                if (r180 != 0 || r0 != 0)
                {
                    mouse = mouse.Rotate(315);
                }
                else
                {
                    mouse = mouse.Rotate(270);
                }
            }
            if (r180 != 0)
            {
                mouse *= -1;
            }

            return(mouse);
        }
예제 #21
0
        public override TouchState ReadValue(ref InputBindingCompositeContext context)
        {
            var touch1 = context.ReadValue <TouchState, TouchStateComparer>(Finger1);
            var touch2 = context.ReadValue <TouchState, TouchStateComparer>(Finger2);

            if (!touch1.isInProgress)
            {
                return(touch1);
            }

            if (!touch2.isInProgress)
            {
                return(touch2);
            }

            var median = touch1;

            median.position = (touch1.position + touch2.position) / 2.0f;

            return(median);
        }
        public override TouchState ReadValue(ref InputBindingCompositeContext context)
        {
            var touch1 = context.ReadValue <TouchState, TouchStateComparer>(Finger1);
            var touch2 = context.ReadValue <TouchState, TouchStateComparer>(Finger2);

            if (!touch1.isInProgress)
            {
                return(touch1);
            }

            if (!touch2.isInProgress)
            {
                return(touch2);
            }

            var distance = touch1;

            distance.position = touch1.position - touch2.position;

            return(distance);
        }
예제 #23
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);
            }
        }
예제 #24
0
        public override Vector2 ReadValue(ref InputBindingCompositeContext context)
        {
            totalDelta += context.ReadValue <Vector2, Vector2MagnitudeComparer>(Delta);

            if (Mathf.Abs(totalDelta.x) < MinDistance && Mathf.Abs(totalDelta.y) < MinDistance)
            {
                return(Vector2.zero);
            }

            switch (ReturnValueType)
            {
            case ValueType.Delta:
                return(totalDelta);

            case ValueType.OneUnitInt:
                return(new Vector2(totalDelta.x > 0 ? 1 : -1, totalDelta.y > 0 ? 1 : -1));

            case ValueType.NormalisedDelta:
            default:
                return(totalDelta.normalized);
            }
        }
예제 #25
0
        public override PointerInput ReadValue(ref InputBindingCompositeContext context)
        {
            var contact   = context.ReadValueAsButton(this.contact);
            var pointerId = context.ReadValue <int>(inputId);
            var pressure  = context.ReadValue <float>(this.pressure);
            var radius    = context.ReadValue <Vector2, Vector2MagnitudeComparer>(this.radius);
            var tilt      = context.ReadValue <Vector2, Vector2MagnitudeComparer>(this.tilt);
            var position  = context.ReadValue <Vector2, Vector2MagnitudeComparer>(this.position);
            var twist     = context.ReadValue <float>(this.twist);

            return(new PointerInput
            {
                Contact = contact,
                InputId = pointerId,
                Position = position,
                Tilt = tilt != default ? tilt : (Vector2?)null,
                Pressure = pressure > 0 ? pressure : (float?)null,
                Radius = radius.sqrMagnitude > 0 ? radius : (Vector2?)null,
                Twist = twist > 0 ? twist : (float?)null,
            });
 /// <summary>
 /// Return the value of the <see cref="button"/> part multiplied by 1 or -1 depending if <see cref="modifier"/> is pressed.
 /// </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)
 {
     return(context.ReadValue <float>(button) * (context.ReadValueAsButton(modifier) ? -1 : 1));
 }
예제 #27
0
        public override Vector2 ReadValue(ref InputBindingCompositeContext context)
        {
            var condition = context.ReadValue <float>(ConditionalButton);

            return(new Vector2(-context.ReadValue <float>(X) / 5f, -context.ReadValue <float>(Y) / 5f) * condition);
        }
 public override Vector2 ReadValue(ref InputBindingCompositeContext context)
 {
     return(context.ReadValueAsButton(button) ? context.ReadValue <Vector2, Vector2MagnitudeComparer>(delta) : default);
        // This method computes the current actuation of the binding as a whole.
        public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
        {
            var mouse = context.ReadValue <Vector2, CustomVector2Comparer>(MouseInput, comparer);

            return(mouse.magnitude);
        }
 public override float ReadValue(ref InputBindingCompositeContext context)
 {
     return(context.ReadValue <float, LowestMagnitudeFloatComparer>(modifier) != 0f ? context.ReadValue <float, HighestMagnitudeFloatComparer>(axis) : default);