Exemplo n.º 1
0
        public bool SetMouse(ActionSetting.MouseAction mouse, string description)
        {
            //Debug.Log("Set mouse: " + mouse.ToString() + " in " + name);

            Reset();

            DescriptionLabel.enabled = true;
            DescriptionLabel.text    = description;

            bool result = true;

            MouseIconBase.enabled = true;
            switch (mouse)
            {
            case ActionSetting.MouseAction.Left:
                MouseIconLeftButton.enabled = true;
                break;

            case ActionSetting.MouseAction.Right:
                MouseIconRightButton.enabled = true;
                break;

            case ActionSetting.MouseAction.Middle:
                MouseIconMiddleButton.enabled = true;
                break;

            default:
                result = false;
                break;
            }

            return(result);
        }
Exemplo n.º 2
0
        public UserKeyboardAndMouseProfile(ActionManager <T> u) : base()
        {
            // This profile only works on desktops.
            SupportedPlatforms = new[] {
                "Windows",
                "Mac",
                "Linux"
            };

            Sensitivity   = 1.0f;
            LowerDeadZone = 0.0f;
            UpperDeadZone = 1.0f;

            Name = u.GetType().Name;

            List <InputControlMapping> analogMappings = new List <InputControlMapping> ();
            List <InputControlMapping> buttonMappings = new List <InputControlMapping> ();
            KeyCode key  = KeyCode.None;
            KeyCode keyX = KeyCode.None;
            KeyCode keyY = KeyCode.None;

            ActionSetting.MouseAction mouse = ActionSetting.MouseAction.None;

            #region scroll wheel
            //bind our scroll wheel to the scroll wheel axis
            switch (u.ScrollWheelAxis)
            {
            case InputControlType.DPadX:
                analogMappings.Add(
                    new InputControlMapping {
                    Handle      = "Look Z X",
                    Target      = InputControlType.DPadRight,
                    Source      = MouseScrollWheel,
                    Raw         = true,
                    SourceRange = InputRange.ZeroToNegativeInfinity
                }
                    );
                analogMappings.Add(
                    new InputControlMapping {
                    Handle      = "Look Z Y",
                    Target      = InputControlType.DPadLeft,
                    Source      = MouseScrollWheel,
                    Raw         = true,
                    SourceRange = InputRange.ZeroToPositiveInfinity
                }
                    );
                break;

            case InputControlType.DPadY:
                analogMappings.Add(
                    new InputControlMapping {
                    Handle      = "Look Z X",
                    Target      = InputControlType.DPadUp,
                    Source      = MouseScrollWheel,
                    Raw         = true,
                    SourceRange = InputRange.ZeroToNegativeInfinity
                }
                    );
                analogMappings.Add(
                    new InputControlMapping {
                    Handle      = "Look Z Y",
                    Target      = InputControlType.DPadDown,
                    Source      = MouseScrollWheel,
                    Raw         = true,
                    SourceRange = InputRange.ZeroToPositiveInfinity
                }
                    );
                break;

            default:
                analogMappings.Add(
                    new InputControlMapping {
                    Handle = "Look Z",
                    Target = u.ScrollWheelAxis,
                    Source = MouseScrollWheel,
                    Raw    = true,
                }
                    );
                break;
            }
            #endregion

            #region axis mappings
            //bind keys to our axis
            if (u.GetKeyAxis(u.ScrollWheelAxis, ref keyX, ref keyY))
            {
                switch (u.ScrollWheelAxis)
                {
                case InputControlType.DPadX:
                    buttonMappings.Add(
                        new InputControlMapping {
                        Handle = "Scroll Right",
                        Target = InputControlType.DPadRight,
                        Source = new UnityKeyCodeSource(keyX)
                    }
                        );
                    buttonMappings.Add(
                        new InputControlMapping {
                        Handle = "Scroll Left",
                        Target = InputControlType.DPadLeft,
                        Source = new UnityKeyCodeSource(keyY)
                    }
                        );
                    break;

                case InputControlType.DPadY:
                    buttonMappings.Add(
                        new InputControlMapping {
                        Handle = "Scroll Right",
                        Target = InputControlType.DPadUp,
                        Source = new UnityKeyCodeSource(keyX)
                    }
                        );
                    buttonMappings.Add(
                        new InputControlMapping {
                        Handle = "Scroll Left",
                        Target = InputControlType.DPadDown,
                        Source = new UnityKeyCodeSource(keyY)
                    }
                        );
                    break;

                default:
                    analogMappings.Add(
                        new InputControlMapping {
                        Handle = "Scroll left / right",
                        Target = u.ScrollWheelAxis,
                        Source = new UnityKeyCodeAxisSource(keyX, keyY)
                    }
                        );
                    break;
                }
            }

            /*if (u.GetKeyAxis (u.MovementXAxis, ref keyX, ref keyY)) {
             *      switch (u.MovementXAxis) {
             *      case InputControlType.DPadX:
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Move Right",
             *                              Target = InputControlType.DPadRight,
             *                      Source = new UnityKeyCodeSource (keyX)
             *                      }
             *              );
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Move Left",
             *                              Target = InputControlType.DPadLeft,
             *                      Source = new UnityKeyCodeSource (keyY)
             *                      }
             *              );
             *              break;
             *
             *      case InputControlType.DPadY:
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Move Right",
             *                              Target = InputControlType.DPadUp,
             *                      Source = new UnityKeyCodeSource (keyX)
             *                      }
             *              );
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Move Left",
             *                              Target = InputControlType.DPadDown,
             *                      Source = new UnityKeyCodeSource (keyY)
             *                      }
             *              );
             *              break;
             *
             *      default:
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Move left / right",
             *                              Target = u.MovementXAxis,
             *                              Source = new UnityKeyCodeAxisSource (keyX, keyY)
             *                      }
             *              );
             *              break;
             *      }
             * }*/

            /*if (u.GetKeyAxis (u.MovementYAxis, ref keyX, ref keyY)) {
             *      switch (u.MovementYAxis) {
             *      case InputControlType.DPadX:
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Move Forward",
             *                              Target = InputControlType.DPadRight,
             *                      Source = new UnityKeyCodeSource (keyX)
             *                      }
             *              );
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Move Back",
             *                              Target = InputControlType.DPadLeft,
             *                      Source = new UnityKeyCodeSource (keyY)
             *                      }
             *              );
             *              break;
             *
             *      case InputControlType.DPadY:
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Move Forward",
             *                              Target = InputControlType.DPadUp,
             *                      Source = new UnityKeyCodeSource (keyX)
             *                      }
             *              );
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Move Back",
             *                              Target = InputControlType.DPadDown,
             *                              Source = new UnityKeyCodeSource (keyY)
             *                      }
             *              );
             *              break;
             *
             *
             *      default:
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Move forward / back",
             *                              Target = u.MovementYAxis,
             *                              Source = new UnityKeyCodeAxisSource (keyX, keyY)
             *                      }
             *              );
             *              break;
             *      }
             * }*/

            /*if (u.MouseXAxis != InputControlType.None) {
             *      switch (u.MovementYAxis) {
             *      case InputControlType.DPadX:
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Mouse X X",
             *                              Target = InputControlType.DPadRight,
             *                              Source = KeyCodeButton (keyX)
             *                      }
             *              );
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Mouse X Y",
             *                              Target = InputControlType.DPadLeft,
             *                              Source = KeyCodeButton (keyY)
             *                      }
             *              );
             *              break;
             *
             *      case InputControlType.DPadY:
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Mouse X X",
             *                              Target = InputControlType.DPadUp,
             *                              Source = KeyCodeButton (keyX)
             *                      }
             *              );
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Mouse X Y",
             *                              Target = InputControlType.DPadDown,
             *                              Source = KeyCodeButton (keyY)
             *                      }
             *              );
             *              break;
             *
             *
             *      default:
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Mouse X axis",
             *                              Target = u.MouseXAxis,
             *                              Source = MouseXAxis,
             *                              Scale = 0.1f,
             *                              Raw = true,
             *                      }
             *              );
             *              break;
             *      }
             * }*/

            /*if (u.MouseYAxis != InputControlType.None) {
             *      switch (u.MovementYAxis) {
             *      case InputControlType.DPadX:
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Mouse Y X",
             *                              Target = InputControlType.DPadRight,
             *                              Source = KeyCodeButton (keyX)
             *                      }
             *              );
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Mouse Y Y",
             *                              Target = InputControlType.DPadLeft,
             *                              Source = KeyCodeButton (keyY)
             *                      }
             *              );
             *              break;
             *
             *      case InputControlType.DPadY:
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Mouse Y X",
             *                              Target = InputControlType.DPadUp,
             *                              Source = KeyCodeButton (keyX)
             *                      }
             *              );
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Mouse Y Y",
             *                              Target = InputControlType.DPadDown,
             *                              Source = KeyCodeButton (keyY)
             *                      }
             *              );
             *              break;
             *
             *      default:
             *
             *              analogMappings.Add (
             *                      new InputControlMapping {
             *                              Handle = "Mouse Y axis",
             *                              Target = u.MouseYAxis,
             *                              Source = MouseYAxis,
             *                              Scale = 0.1f,
             *                              Raw = true,
             *                      }
             *              );
             *              break;
             *      }
             * }*/

            #endregion

            #region button mappings

            List <InputControlMapping> mappings = null;
            foreach (ActionSetting a in u.CurrentActionSettings)
            {
                float lowerDeadZone = -1f;
                float upperDeadZone = 1f;

                if (a.IsAnalog)
                {
                    mappings = analogMappings;
                }
                else
                {
                    mappings = buttonMappings;
                }
                //if this has a controller setting
                if (a.Controller != InputControlType.None)
                {
                    //bind it to mouse and keys
                    if (a.Key != KeyCode.None)
                    {
                        //Debug.Log("Binding " + a.ActionDescription + " to key " + a.Key.ToString() + " - mouse is " + a.Mouse.ToString());
                        switch (a.Controller)
                        {
                        case InputControlType.LeftStickUp:
                        case InputControlType.LeftStickDown:
                        case InputControlType.LeftStickLeft:
                        case InputControlType.LeftStickRight:
                            lowerDeadZone = Profile.Get.CurrentPreferences.Controls.DeadZoneLStickLower;
                            upperDeadZone = Profile.Get.CurrentPreferences.Controls.DeadZoneLStickUpper;
                            break;

                        case InputControlType.RightStickUp:
                        case InputControlType.RightStickDown:
                        case InputControlType.RightStickLeft:
                        case InputControlType.RightStickRight:
                            lowerDeadZone = Profile.Get.CurrentPreferences.Controls.DeadZoneRStickLower;
                            upperDeadZone = Profile.Get.CurrentPreferences.Controls.DeadZoneRStickUpper;
                            break;

                        case InputControlType.DPadUp:
                        case InputControlType.DPadDown:
                        case InputControlType.DPadLeft:
                        case InputControlType.DPadRight:
                            lowerDeadZone = Profile.Get.CurrentPreferences.Controls.DeadZoneDPadLower;
                            upperDeadZone = Profile.Get.CurrentPreferences.Controls.DeadZoneDPadUpper;
                            break;

                        default:
                            break;
                        }
                        mappings.Add(new InputControlMapping {
                            Handle        = a.ActionDescription,
                            Target        = a.Controller,
                            Source        = KeyCodeButton(a.Key),
                            SourceRange   = InputRange.ZeroToOne,
                            TargetRange   = InputRange.ZeroToOne,
                            UpperDeadZone = upperDeadZone,
                            LowerDeadZone = lowerDeadZone
                        }
                                     );
                    }

                    switch (a.Mouse)
                    {
                    case ActionSetting.MouseAction.Left:
                        mappings.Add(
                            new InputControlMapping {
                            Handle = a.ActionDescription,
                            Target = a.Controller,
                            Source = MouseButton0
                        }
                            );
                        break;

                    case ActionSetting.MouseAction.Right:
                        mappings.Add(
                            new InputControlMapping {
                            Handle = a.ActionDescription,
                            Target = a.Controller,
                            Source = MouseButton1
                        }
                            );
                        break;

                    case ActionSetting.MouseAction.Middle:
                        mappings.Add(
                            new InputControlMapping {
                            Handle = a.ActionDescription,
                            Target = a.Controller,
                            Source = MouseButton2
                        }
                            );
                        break;

                    default:
                        //other keys are descriptive, don't bind them
                        break;
                    }
                }
            }

            #endregion

            AnalogMappings = analogMappings.ToArray();
            ButtonMappings = buttonMappings.ToArray();
        }