Example #1
0
        public bool GetButtonUp(string name)
        {
            ControllerBind bind = GetBind(name);

            if (bind == null)
            {
                return(false);
            }

            if (!bind.isKey)
            {
                string axisName = Controls.GetAxisName(JoyStick, bind.axisNumber);
                for (int i = 0; i < releasedAxes.Count; i++)
                {
                    if (releasedAxes[i] == axisName)
                    {
                        return(true);
                    }
                }

                return(false);
            }
            else
            {
                string buttonName = Controls.GetButtonName(JoyStick, bind.buttonNumber);
                return(Input.GetKeyUp(buttonName));
            }
        }
Example #2
0
        public bool GetButton(ControllerBind bind, int joyStick)
        {
            if (bind == null)
            {
                return(false);
            }

            if (!bind.isKey)
            {
                return(bind.Evaluate(joyStick));
            }
            else
            {
                string buttonName = Controls.GetButtonName(joyStick, bind.buttonNumber);
                return(Input.GetKey(buttonName));
            }
        }
Example #3
0
        private void Update()
        {
            Map = map;
            DefaultController = defaultController;

            //set static value
            Controls.Controllers = controllers;
            joysticks            = Input.GetJoystickNames();
            if (joysticks.Length > 0)
            {
                //load controllers
                controllers.Clear();
                int index    = 0;
                int joyStick = 0;
                for (int j = 0; j < joysticks.Length; j++)
                {
                    ControllerType type = GetController(joysticks[j]);
                    if (type != null)
                    {
                        Controller controller = new Controller(type, j);
                        controllers.Add(controller);
                        joyStick++;

                        for (int b = 0; b < type.buttons.Count; b++)
                        {
                            ControllerBind bind = type.buttons[b];
                            if (!bind.isKey)
                            {
                                string axisName  = Controls.GetAxisName(controller.JoyStick, bind.axisNumber);
                                float  axisValue = Input.GetAxisRaw(axisName);
                                if (axisValue != lastAxis[index])
                                {
                                    if (Mathf.Abs(axisValue) < 0.2f)
                                    {
                                        controller.ReleaseAxis(axisName);
                                    }
                                    else
                                    {
                                        if (bind.axisDirection == ControllerAxisDirection.Both)
                                        {
                                            if (Mathf.Abs(axisValue) > 0.2f)
                                            {
                                                axisName += ".Both";
                                                controller.PressAxis(axisName);
                                            }
                                        }
                                        else if (bind.axisDirection == ControllerAxisDirection.Negative)
                                        {
                                            if (axisValue < -0.2f)
                                            {
                                                axisName += ".Negative";
                                                controller.PressAxis(axisName);
                                            }
                                        }
                                        else if (bind.axisDirection == ControllerAxisDirection.Positive)
                                        {
                                            if (axisValue > 0.2f)
                                            {
                                                axisName += ".Positive";
                                                controller.PressAxis(axisName);
                                            }
                                        }
                                    }

                                    lastAxis[index] = axisValue;
                                    index++;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                controllers.Clear();
            }

            //if no controllers, add default
            if (controllers.Count == 0)
            {
                Controller controller = new Controller(defaultController, 0);
                controllers.Add(controller);
            }
        }
Example #4
0
        public bool GetButton(string name)
        {
            ControllerBind bind = GetBind(name);

            return(Type.GetButton(bind, JoyStick));
        }