Пример #1
0
            private static InputMap <WingsuitAction, float> DerivableAxisInput(InputMap <WingsuitAction, float> axisInput)
            {
                var derivedInput = ImmutableDictionary <WingsuitAction, Func <float> > .Empty;

                var closeArms     = axisInput.Source.GetValueOrDefault(WingsuitAction.CloseArms, () => 0.0f);
                var closeLeftArm  = axisInput.Source.GetValueOrDefault(WingsuitAction.CloseLeftArm, () => 0.0f);
                var closeRightArm = axisInput.Source.GetValueOrDefault(WingsuitAction.CloseRightArm, () => 0.0f);

                derivedInput = derivedInput
                               .SetItem(WingsuitAction.CloseLeftArm, ImperoCore.MergePollFns(Adapters.MergeAxes, new[] { closeArms, closeLeftArm }));
                derivedInput = derivedInput
                               .SetItem(WingsuitAction.CloseRightArm, ImperoCore.MergePollFns(Adapters.MergeAxes, new[] { closeArms, closeRightArm }));

                foreach (var derivable in PilotActionDetails.DerivableActions)
                {
                    var positiveAction = axisInput.Source
                                         .GetValueOrDefault(derivable.Value.Positive, () => 0.0f);
                    var negativeAction = axisInput.Source
                                         .GetValueOrDefault(derivable.Value.Negative, () => 0.0f)
                                         .Adapt <float, float>(Adapters.Invert);
                    derivedInput = derivedInput.SetItem(derivable.Key, ImperoCore.MergePollFns(Adapters.MergeAxes,
                                                                                               new[] { negativeAction, positiveAction }));
                }

                return(derivedInput.ToInputMap());
            }
Пример #2
0
    void Awake()
    {
        var mouseInput = ImperoCore.MergeAll(
            Adapters.MergeButtons,
            Peripherals.Mouse.Buttons,
            Peripherals.Mouse.Axes.Adapt(Adapters.Axis2Button(_activityThreshold)));

        _mouseActivity = ImperoCore.MergePollFns(Adapters.MergeButtons, mouseInput.Source.Values)
                         .Adapt(buttonState => buttonState == ButtonState.Pressed);
    }
Пример #3
0
        public TitleScreen(IStateMachine machine, Data data) : base(machine)
        {
            _data = data;
            _data.TitleScreenLogo.SetActive(false); // Note: due to obscure crashbug, this has to be active in the serialized scene

            var buttonInput = ImperoCore
                              .MergeAll(
                Adapters.MergeButtons,
                UnityInputIds.ControllerIds.Select(joystickId => Peripherals.Controller.Buttons(joystickId))
                .Concat(new [] { Peripherals.Keyboard, Peripherals.Mouse.Buttons }));

            _buttonEvents = ImperoCore
                            .MergePollFns(Adapters.MergeButtons, buttonInput.Source.Values)
                            .Adapt(Adapters.ButtonEvents(() => Time.frameCount));
        }
Пример #4
0
        public static ParachuteActionMap Create(ActionMapConfig <ParachuteAction> actionMapConfig, float axisButtonThreshold = 0.5f)
        {
            var inputSettings = actionMapConfig.InputSettings;
            var inputMapping  = actionMapConfig.InputMapping;

            var controllerPeripheral = Peripherals.Controller.GetPeripheral(actionMapConfig.ControllerId,
                                                                            inputSettings);

            var buttonInputSource = ImperoCore.MergeAll(
                Adapters.MergeButtons,
                Peripherals.Keyboard,
                Peripherals.Mouse.Buttons,
                controllerPeripheral.Buttons);

            var inputWithAxisSource      = inputMapping.ApplyMapping(controllerPeripheral.Axes, Adapters.MergeAxes);
            var inputWithMouseAxisSource = inputMapping.ApplyMapping(Peripherals.Mouse.PolarizedAxes, Adapters.MergeAxes);
            var inputWithButtonSource    = inputMapping.ApplyMapping(buttonInputSource, Adapters.MergeButtons);

            bool isMouseInput = inputWithMouseAxisSource.Source.ContainsKey(ParachuteAction.PullBothLines) ||
                                inputWithMouseAxisSource.Source.ContainsKey(ParachuteAction.PullLeftLines) ||
                                inputWithMouseAxisSource.Source.ContainsKey(ParachuteAction.PullRightLines);

            // Finally merge all input maps
            Debug.Log("parachute sensitivity: " + inputSettings.ParachuteMouseSensitivity);
            var axisInput = ImperoCore.MergeAll(
                Adapters.MergeAxes,
                inputWithAxisSource,
                inputWithMouseAxisSource
                .Adapt(Adapters.ApplySensitivity(inputSettings.ParachuteMouseSensitivity))
                .Adapt(ParachuteAction.PullBothLines, Adapters.Deadzone(deadzone: 0.1f)),
                // TODO Instead of button2axis use gradual button2axis
                inputWithButtonSource.Adapt <ParachuteAction, ButtonState, float>(Adapters.Button2Axis));
            var buttonInput = ImperoCore.MergeAll(
                Adapters.MergeButtons,
                inputWithButtonSource,
                inputWithMouseAxisSource.Adapt(Adapters.Axis2Button(3f)),
                inputWithAxisSource.Adapt <ParachuteAction, float, ButtonState>(Adapters.Axis2Button(axisButtonThreshold)));

            axisInput = axisInput.FillEmptyValues(ParachuteActionDetails.MappableActions,
                                                  () => 0.0f);
            buttonInput = buttonInput.FillEmptyValues(ParachuteActionDetails.MappableActions,
                                                      () => ButtonState.Released);

            Func <Vector2> weightShift;
            {
                var horizontalShiftLeft  = axisInput.Source[ParachuteAction.WeightShiftLeft];
                var horizontalShiftRight = axisInput.Source[ParachuteAction.WeightShiftRight];
                var verticalShiftFront   = axisInput.Source[ParachuteAction.WeightShiftFront];
                var verticalShiftBack    = axisInput.Source[ParachuteAction.WeightShiftBack];
                weightShift = () => new Vector2(
                    horizontalShiftRight() - horizontalShiftLeft(),
                    verticalShiftFront() - verticalShiftBack());
            }

            Func <ParachuteLine> pollSelectedLine;
            Func <Vector2>       pullBrakeLines;
            Func <Vector2>       pullRearLines;
            Func <Vector2>       pullFrontLines;
            {
                var            pullLeft  = axisInput.Source[ParachuteAction.PullLeftLines];
                var            pullRight = axisInput.Source[ParachuteAction.PullRightLines];
                var            pullBoth  = axisInput.Source[ParachuteAction.PullBothLines];
                Func <Vector2> pullLines = () => {
                    var linePull  = pullBoth();
                    var leftPull  = Mathf.Max(linePull, pullLeft());
                    var rightPull = Mathf.Max(linePull, pullRight());
                    return(new Vector2(leftPull, rightPull));
                };

                var toggleFrontlines = buttonInput.Source[ParachuteAction.HoldFrontLines];
                var toggleRearlines  = buttonInput.Source[ParachuteAction.HoldRearLines];

                pollSelectedLine = () => {
                    if (toggleFrontlines() == ButtonState.Pressed)
                    {
                        return(ParachuteLine.Front);
                    }
                    if (toggleRearlines() == ButtonState.Pressed)
                    {
                        return(ParachuteLine.Rear);
                    }
                    return(ParachuteLine.Brake);
                };

                pullBrakeLines = ImperoCore.MergePollFns(
                    Adapters.MergeAxes,
                    FilterInput(pullLines, v => pollSelectedLine() == ParachuteLine.Brake),
                    CombineAxes(axisInput, ParachuteAction.PullBrakeLineLeft, ParachuteAction.PullBrakeLineRight));
                pullRearLines = ImperoCore.MergePollFns(
                    Adapters.MergeAxes,
                    FilterInput(pullLines, v => pollSelectedLine() == ParachuteLine.Rear),
                    CombineAxes(axisInput, ParachuteAction.PullRearLineLeft, ParachuteAction.PullRearLineRight));
                pullFrontLines = ImperoCore.MergePollFns(
                    Adapters.MergeAxes,
                    FilterInput(pullLines, v => pollSelectedLine() == ParachuteLine.Front),
                    CombineAxes(axisInput, ParachuteAction.PullFrontLineLeft, ParachuteAction.PullFrontLineRight));
            }

//            var configToggle = buttonInput.Source[ParachuteAction.ParachuteConfigToggle]
//                .Adapt(Adapters.ButtonEvents(() => Time.frameCount));
            Func <ButtonEvent>    configToggle       = () => ButtonEvent.Nothing;
            Func <ParachuteInput> pollParachuteInput = () => {
                var     selectedLine = pollSelectedLine();
                Vector2 brakes       = pullBrakeLines();
                Vector2 rearLines    = pullRearLines();
                Vector2 frontLines   = pullFrontLines();
                return(new ParachuteInput(selectedLine, brakes, rearLines, frontLines, weightShift(), isMouseInput));
            };

            return(new ParachuteActionMap(pollParachuteInput, configToggle));
        }