Esempio n. 1
0
        public static bool GetButtonUp(string name, PlayerID playerID = PlayerID.One)
        {
            AxisConfiguration axisConfig = GetAxisConfiguration(playerID, name);

            if (axisConfig != null)
            {
                return(axisConfig.GetButtonUp());
            }
            else
            {
                Debug.LogError(string.Format("An button named \'{0}\' does not exist in the active input configuration for player {1}", name, playerID));
                return(false);
            }
        }
Esempio n. 2
0
        public static InputConfiguration Duplicate(InputConfiguration source)
        {
            InputConfiguration inputConfig = new InputConfiguration();

            inputConfig.name = source.name;

            inputConfig.axes = new List <AxisConfiguration>(source.axes.Count);
            for (int i = 0; i < source.axes.Count; i++)
            {
                inputConfig.axes.Add(AxisConfiguration.Duplicate(source.axes[i]));
            }

            return(inputConfig);
        }
Esempio n. 3
0
        public static float GetAxisRaw(string name, PlayerID playerID = PlayerID.One)
        {
            AxisConfiguration axisConfig = GetAxisConfiguration(playerID, name);

            if (axisConfig != null)
            {
                return(axisConfig.GetAxisRaw());
            }
            else
            {
                Debug.LogError(string.Format("An axis named \'{0}\' does not exist in the active input configuration for player {1}", name, playerID));
                return(0.0f);
            }
        }
Esempio n. 4
0
 public void Copy(AxisConfiguration source)
 {
     name        = source.name;
     description = source.description;
     positive    = source.positive;
     altPositive = source.altPositive;
     negative    = source.negative;
     altNegative = source.altNegative;
     deadZone    = source.deadZone;
     gravity     = source.gravity;
     sensitivity = source.sensitivity;
     snap        = source.snap;
     invert      = source.invert;
     type        = source.type;
     axis        = source.axis;
     joystick    = source.joystick;
 }
Esempio n. 5
0
        private void WriteAxisConfiguration(AxisConfiguration axisConfig, XmlWriter writer)
        {
            writer.WriteStartElement("AxisConfiguration");
            writer.WriteAttributeString("name", axisConfig.name);
            writer.WriteElementString("description", axisConfig.description);
            writer.WriteElementString("positive", axisConfig.positive.ToString());
            writer.WriteElementString("altPositive", axisConfig.altPositive.ToString());
            writer.WriteElementString("negative", axisConfig.negative.ToString());
            writer.WriteElementString("altNegative", axisConfig.altNegative.ToString());
            writer.WriteElementString("deadZone", axisConfig.deadZone.ToString());
            writer.WriteElementString("gravity", axisConfig.gravity.ToString());
            writer.WriteElementString("sensitivity", axisConfig.sensitivity.ToString());
            writer.WriteElementString("snap", axisConfig.snap.ToString().ToLower());
            writer.WriteElementString("invert", axisConfig.invert.ToString().ToLower());
            writer.WriteElementString("type", axisConfig.type.ToString());
            writer.WriteElementString("axis", axisConfig.axis.ToString());
            writer.WriteElementString("joystick", axisConfig.joystick.ToString());

            writer.WriteEndElement();
        }
Esempio n. 6
0
        public static AxisConfiguration Duplicate(AxisConfiguration source)
        {
            AxisConfiguration axisConfig = new AxisConfiguration();

            axisConfig.name        = source.name;
            axisConfig.description = source.description;
            axisConfig.positive    = source.positive;
            axisConfig.altPositive = source.altPositive;
            axisConfig.negative    = source.negative;
            axisConfig.altNegative = source.altNegative;
            axisConfig.deadZone    = source.deadZone;
            axisConfig.gravity     = source.gravity;
            axisConfig.sensitivity = source.sensitivity;
            axisConfig.snap        = source.snap;
            axisConfig.invert      = source.invert;
            axisConfig.type        = source.type;
            axisConfig.axis        = source.axis;
            axisConfig.joystick    = source.joystick;

            return(axisConfig);
        }
Esempio n. 7
0
        private AxisConfiguration ReadAxisConfiguration(XmlNode node)
        {
            AxisConfiguration axisConfig = new AxisConfiguration();

            axisConfig.name = ReadAttribute(node, "name", "Unnamed Axis");

            foreach (XmlNode child in node.ChildNodes)
            {
                switch (child.LocalName)
                {
                case "description":
                    axisConfig.description = child.InnerText;
                    break;

                case "positive":
                    axisConfig.positive = AxisConfiguration.StringToKey(child.InnerText);
                    break;

                case "altPositive":
                    axisConfig.altPositive = AxisConfiguration.StringToKey(child.InnerText);
                    break;

                case "negative":
                    axisConfig.negative = AxisConfiguration.StringToKey(child.InnerText);
                    break;

                case "altNegative":
                    axisConfig.altNegative = AxisConfiguration.StringToKey(child.InnerText);
                    break;

                case "deadZone":
                    axisConfig.deadZone = ReadAsFloat(child);
                    break;

                case "gravity":
                    axisConfig.gravity = ReadAsFloat(child, 1.0f);
                    break;

                case "sensitivity":
                    axisConfig.sensitivity = ReadAsFloat(child, 1.0f);
                    break;

                case "snap":
                    axisConfig.snap = ReadAsBool(child);
                    break;

                case "invert":
                    axisConfig.invert = ReadAsBool(child);
                    break;

                case "type":
                    axisConfig.type = AxisConfiguration.StringToInputType(child.InnerText);
                    break;

                case "axis":
                    axisConfig.axis = ReadAsInt(child);
                    break;

                case "joystick":
                    axisConfig.joystick = ReadAsInt(child);
                    break;
                }
            }

            return(axisConfig);
        }
Esempio n. 8
0
        private void Start()
        {
            InputConfiguration inputConfig = InputManager.GetInputConfiguration(_inputConfiguration);

            if (inputConfig == null)
            {
                Debug.LogWarning(string.Format("An input configuration named \'{0}\' does not exist", _inputConfiguration), this);
                return;
            }

            int axisCount           = inputConfig.axes.Count;
            int joystickButtonCount = (int)KeyCode.Joystick1Button19 - (int)KeyCode.Joystick1Button0 + 1;

            //	All new axes will be added at the end of the list so it's safe to iterate normally to
            //	the initial number of axes
            for (int i = 0; i < axisCount; i++)
            {
                AxisConfiguration orig = inputConfig.axes[i];
                if (!orig.name.EndsWith("_P1"))
                {
                    continue;
                }

                if (orig.joystick > 0)
                {
                    Debug.LogError(string.Format("Cannot clone axis {0} of configuration {1} because joystick is {2} instead of 0", orig.name, _inputConfiguration, orig.joystick), this);
                    continue;
                }

                if ((orig.positive != KeyCode.None && ((int)orig.positive < (int)KeyCode.Joystick1Button0 || (int)orig.positive > (int)KeyCode.Joystick1Button19)) ||
                    (orig.altPositive != KeyCode.None && ((int)orig.altPositive < (int)KeyCode.Joystick1Button0 || (int)orig.altPositive > (int)KeyCode.Joystick1Button19)) ||
                    (orig.negative != KeyCode.None && ((int)orig.negative < (int)KeyCode.Joystick1Button0 || (int)orig.negative > (int)KeyCode.Joystick1Button19)) ||
                    (orig.altNegative != KeyCode.None && ((int)orig.altNegative < (int)KeyCode.Joystick1Button0 || (int)orig.altNegative > (int)KeyCode.Joystick1Button19)))
                {
                    Debug.LogError(string.Format("Cannot clone axis {0} of configuration {1} because some key codes are invalid", orig.name, _inputConfiguration), this);
                    continue;
                }

                for (int c = 0; c < _numberOfClones; c++)
                {
                    string            axisName = orig.name.Substring(0, orig.name.Length - 3) + "_P" + (c + 2);
                    AxisConfiguration clone    = InputManager.CreateEmptyAxis(_inputConfiguration, axisName);
                    clone.Copy(orig);
                    clone.name = axisName;
                    if (orig.positive != KeyCode.None)
                    {
                        clone.positive = (KeyCode)((int)orig.positive + (c + 1) * joystickButtonCount);
                    }
                    if (orig.altPositive != KeyCode.None)
                    {
                        clone.altPositive = (KeyCode)((int)orig.altPositive + (c + 1) * joystickButtonCount);
                    }
                    if (orig.negative != KeyCode.None)
                    {
                        clone.negative = (KeyCode)((int)orig.negative + (c + 1) * joystickButtonCount);
                    }
                    if (orig.altNegative != KeyCode.None)
                    {
                        clone.altNegative = (KeyCode)((int)orig.altNegative + (c + 1) * joystickButtonCount);
                    }
                    clone.joystick = c + 1;
                    clone.Initialize();
                }
            }
        }