Пример #1
0
        public static List <DeviceInput> GetApplicableMaps(CommonGamepadInputs t, string[] connectedGamepads)
        {
            //builds input mapping of type t for all known connected gamepads


            List <DeviceInput> applicableInputs = new List <DeviceInput>();


            for (int i = 0; i < commonMappings.Count; i++)
            {
                //add any applicable button mappings
                for (int k = 0; k < commonMappings[i].buttons.Count; k++)
                {
                    if (commonMappings[i].buttons[k].buttonType == t)
                    {
                        //add this button input
                        DeviceInput newInput = new DeviceInput(InputDeviceType.GamepadButton);
                        newInput.gamepadButtonNumber = commonMappings[i].buttons[k].buttonNumber;
                        newInput.commonMappingType   = t;
                        newInput.displayName         = commonMappings[i].buttons[k].displayName;

                        newInput.allowedSlots = mappingSlots[i].slots.ToArray();

                        applicableInputs.Add(newInput);
                    }
                }
                //add any applicable axis bingings
                for (int k = 0; k < commonMappings[i].axis.Count; k++)
                {
                    if (commonMappings[i].axis[k].buttonType == t)
                    {
                        //add this axis input
                        DeviceInput newInput = new DeviceInput(InputDeviceType.GamepadAxis);
                        newInput.gamepadAxisNumber    = commonMappings[i].axis[k].axisNumber;
                        newInput.commonMappingType    = t;
                        newInput.displayName          = commonMappings[i].axis[k].displayName;
                        newInput.invertAxis           = commonMappings[i].axis[k].invert;
                        newInput.clampAxis            = commonMappings[i].axis[k].clamp;
                        newInput.axisButtoncompareVal = commonMappings[i].axis[k].compareVal;
                        newInput.defaultAxisValue     = commonMappings[i].axis[k].defaultVal;

                        newInput.allowedSlots = mappingSlots[i].slots.ToArray();

                        if (commonMappings[i].axis[k].rescaleAxis)
                        {
                            newInput.rescaleAxis    = true;
                            newInput.rescaleAxisMin = commonMappings[i].axis[k].rescaleAxisMin;
                            newInput.rescaleAxisMax = commonMappings[i].axis[k].rescaleAxisMax;
                        }

                        applicableInputs.Add(newInput);
                    }
                }
            }



            return(applicableInputs);
        }
Пример #2
0
        public void AddKeyboardInput(KeyCode keyCode)
        {
            DeviceInput input = new DeviceInput(InputDeviceType.Keyboard);

            input.keyboardKeyCode   = keyCode;
            input.commonMappingType = CommonGamepadInputs.NOBUTTON;            //don't remove this input when gamepads are unplugged/replugged
            inputs.Add(input);
        }
Пример #3
0
        public void AddMouseInput(MouseInputType mouseInputType)
        {
            DeviceInput input = new DeviceInput(InputDeviceType.Mouse);

            input.mouseInputType    = mouseInputType;
            input.commonMappingType = CommonGamepadInputs.NOBUTTON;
            inputs.Add(input);
        }
Пример #4
0
        public void AddVirtualInput(string virtualInputID)
        {
            DeviceInput input = new DeviceInput(InputDeviceType.Virtual);

            input.virtualInputID    = virtualInputID;
            input.commonMappingType = CommonGamepadInputs.NOBUTTON;
            inputs.Add(input);
            VirtualInputs.AddInput(virtualInputID);
        }
Пример #5
0
        public static Control[] LoadFromString(Control[] schemeToReplace, string loadString)
        {
            //we pass the existing control scheme so that info on needed common bindings can be kept

            //create our new controls list, and add any common bindings we might need to load later when pads are swapped in/out
            List <Control> controls = new List <Control>();

            for (int c = 0; c < schemeToReplace.Length; c++)
            {
                controls.Add(new Control(schemeToReplace[c].name));
                controls[c].commonMappings = new List <CommonGamepadInputs>();
                for (int b = 0; b < schemeToReplace[c].commonMappings.Count; b++)
                {
                    controls[c].commonMappings.Add(schemeToReplace[c].commonMappings[b]);
                }
            }

            //now add saved data to the list (and to other places)
            string[] loadLines = loadString.Split('\n');
            joysticks = Input.GetJoystickNames();
            for (int l = 0; l < loadLines.Length; l++)
            {
                string[] thisLine = loadLines[l].Split(seperator[0]);

                if (thisLine[0] == "controls")
                {
                    int savedControlCount = 0;
                    if (int.TryParse(thisLine[1], out savedControlCount))
                    {
                        for (int c = 0; c < savedControlCount; c++)
                        {
                            l++;
                            //get the string that describes this control
                            thisLine = loadLines[l].Split(seperator[0]);
                            //build the control
                            //Control currentControl = new Control(thisLine[0]);
                            //currentControl.isToggle = thisLine[1] == "True";


                            int currentControlIndex = -1;
                            for (int cc = 0; cc < controls.Count; cc++)
                            {
                                if (controls[cc].name == thisLine[0])
                                {
                                    currentControlIndex = cc;
                                }
                            }
                            if (currentControlIndex == -1)
                            {
                                controls.Add(new Control(thisLine[0]));
                                currentControlIndex = controls.Count - 1;
                            }
                            controls[currentControlIndex].isToggle = thisLine[1] == "True";

                            int savedInputCount = int.Parse(thisLine[2]);

                            //add inputs

                            for (int i = 0; i < savedInputCount; i++)
                            {
                                l++;
                                //get the string that describes this input
                                thisLine = loadLines[l].Split(seperator[0]);
                                //build the input
                                DeviceInput currentInput = new DeviceInput((InputDeviceType)Enum.Parse(typeof(InputDeviceType), thisLine[0]));

                                currentInput.displayName = thisLine[1];
                                currentInput.isCustom    = thisLine[2] == "True";
                                currentInput.deviceName  = thisLine[3];

                                if (currentInput.inputType == InputDeviceType.Keyboard)
                                {
                                    currentInput.keyboardKeyCode = (KeyCode)Enum.Parse(typeof(KeyCode), thisLine[4]);
                                }
                                if (currentInput.inputType == InputDeviceType.Mouse)
                                {
                                    currentInput.mouseInputType = (MouseInputType)Enum.Parse(typeof(MouseInputType), thisLine[4]);
                                }
                                if (currentInput.inputType == InputDeviceType.GamepadButton)
                                {
                                    currentInput.gamepadButtonNumber = int.Parse(thisLine[4]);
                                }
                                if (currentInput.inputType == InputDeviceType.GamepadAxis)
                                {
                                    currentInput.gamepadAxisNumber = int.Parse(thisLine[4]);
                                    currentInput.invertAxis        = thisLine[5] == "True";
                                    currentInput.clampAxis         = thisLine[6] == "True";
                                    currentInput.rescaleAxis       = thisLine[7] == "True";
                                    currentInput.rescaleAxisMin    = float.Parse(thisLine[8]);
                                    currentInput.rescaleAxisMax    = float.Parse(thisLine[9]);
                                }
                                if (currentInput.inputType == InputDeviceType.Virtual)
                                {
                                    currentInput.virtualInputID = thisLine[4];
                                }

                                //lets not forget stuff that isn't saved, but needed anyway
                                currentInput.commonMappingType = CommonGamepadInputs.NOBUTTON;
                                currentInput.defaultAxisValue  = 0f;
                                if (currentInput.inputType == InputDeviceType.GamepadAxis || currentInput.inputType == InputDeviceType.GamepadButton)
                                {
                                    List <int> allowedSlots = new List <int>();
                                    for (int j = 0; j < joysticks.Length; j++)
                                    {
                                        if (joysticks[j].ToUpper() == currentInput.deviceName.ToUpper())
                                        {
                                            allowedSlots.Add(j);
                                        }
                                    }
                                    currentInput.allowedSlots = allowedSlots.ToArray();
                                }


                                //add the input to the control's input list
                                controls[currentControlIndex].inputs.Add(currentInput);
                            }

                            //add this control to the list
                            //controls.Add(currentControl);
                        }
                    }
                    else
                    {
                        Debug.LogError("Can't read number of saved controls.");
                    }
                }

                if (thisLine[0] == "smartcontrols")
                {
                    int savedSmartControlCount = 0;
                    if (int.TryParse(thisLine[1], out savedSmartControlCount))
                    {
                        for (int c = 0; c < savedSmartControlCount; c++)
                        {
                            l++;
                            string currentSmartControl = loadLines[l];

                            //get the inversion settings
                            l++;
                            thisLine = loadLines[l].Split(seperator[0]);
                            for (int i = 0; i < thisLine.Length; i++)
                            {
                                Sinput.SetInverted(currentSmartControl, thisLine[i] == "True", (InputDeviceSlot)i);
                            }

                            //get the scale settings
                            l++;
                            thisLine = loadLines[l].Split(seperator[0]);
                            for (int i = 0; i < thisLine.Length; i++)
                            {
                                Sinput.SetScale(currentSmartControl, float.Parse(thisLine[i]), (InputDeviceSlot)i);
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError("Can't read number of saved smart controls.");
                    }
                }

                if (thisLine[0] == "mouseSensitivity")
                {
                    Sinput.mouseSensitivity = float.Parse(thisLine[1]);
                }
            }


            return(controls.ToArray());
        }
Пример #6
0
        /*public static List<DeviceInput> GetApplicableMaps(CommonXRInputs t, string[] connectedGamepads) {
         *      Debug.LogError("DO THISSSSS");
         *      return new List<DeviceInput>();
         * }*/
        public static List <DeviceInput> GetApplicableMaps(CommonGamepadInputs commonInputType, CommonXRInputs commonXRInputType, string[] connectedGamepads)
        {
            //builds input mapping of type t for all known connected gamepads


            List <DeviceInput> applicableInputs = new List <DeviceInput>();

            bool addthis = false;

            for (int i = 0; i < commonMappings.Count; i++)
            {
                //if (commonMappings[i].isXRdevice) Debug.Log("Found XR device");

                //add any applicable button mappings
                for (int k = 0; k < commonMappings[i].buttons.Count; k++)
                {
                    addthis = false;
                    if (!commonMappings[i].isXRdevice && commonMappings[i].buttons[k].buttonType != CommonGamepadInputs.NOBUTTON)
                    {
                        if (commonMappings[i].buttons[k].buttonType == commonInputType)
                        {
                            addthis = true;
                        }
                    }
                    if (commonMappings[i].isXRdevice && commonMappings[i].buttons[k].vrButtonType != CommonXRInputs.NOBUTTON)
                    {
                        //Debug.Log("Adding XR button from common mapping");
                        if (commonMappings[i].buttons[k].vrButtonType == commonXRInputType)
                        {
                            addthis = true;
                        }
                    }
                    if (addthis)
                    {
                        //add this button input
                        DeviceInput newInput = new DeviceInput(InputDeviceType.GamepadButton);
                        newInput.gamepadButtonNumber = commonMappings[i].buttons[k].buttonNumber;
                        newInput.commonMappingType   = commonInputType;
                        newInput.displayName         = commonMappings[i].buttons[k].displayName;

                        newInput.allowedSlots = mappingSlots[i].slots.ToArray();

                        applicableInputs.Add(newInput);
                    }
                }
                //add any applicable axis bingings
                for (int k = 0; k < commonMappings[i].axis.Count; k++)
                {
                    addthis = false;
                    if (!commonMappings[i].isXRdevice && commonMappings[i].axis[k].buttonType != CommonGamepadInputs.NOBUTTON)
                    {
                        if (commonMappings[i].axis[k].buttonType == commonInputType)
                        {
                            addthis = true;
                        }
                    }
                    if (commonMappings[i].isXRdevice && commonMappings[i].axis[k].vrButtonType != CommonXRInputs.NOBUTTON)
                    {
                        //Debug.Log("Adding XR Axis from common mapping");
                        if (commonMappings[i].axis[k].vrButtonType == commonXRInputType)
                        {
                            addthis = true;
                        }
                    }
                    if (addthis)
                    {
                        //add this axis input
                        DeviceInput newInput = new DeviceInput(InputDeviceType.GamepadAxis);
                        newInput.gamepadAxisNumber    = commonMappings[i].axis[k].axisNumber;
                        newInput.commonMappingType    = commonInputType;
                        newInput.displayName          = commonMappings[i].axis[k].displayName;
                        newInput.invertAxis           = commonMappings[i].axis[k].invert;
                        newInput.clampAxis            = commonMappings[i].axis[k].clamp;
                        newInput.axisButtoncompareVal = commonMappings[i].axis[k].compareVal;
                        newInput.defaultAxisValue     = commonMappings[i].axis[k].defaultVal;

                        newInput.allowedSlots = mappingSlots[i].slots.ToArray();

                        if (commonMappings[i].axis[k].rescaleAxis)
                        {
                            newInput.rescaleAxis    = true;
                            newInput.rescaleAxisMin = commonMappings[i].axis[k].rescaleAxisMin;
                            newInput.rescaleAxisMax = commonMappings[i].axis[k].rescaleAxisMax;
                        }

                        applicableInputs.Add(newInput);
                    }
                }
            }



            return(applicableInputs);
        }