Exemplo n.º 1
0
 public InputAxis(string aName)
 {
     m_PositiveKey = new InputKey(this, true);
     m_NegativeKey = new InputKey(this, false);
     axisName = aName;
 }
Exemplo n.º 2
0
        protected override void onLoad()
        {
            m_PositiveKey = new InputKey(this, true);
            m_NegativeKey = new InputKey(this, false);
            #if UNITY_WEBPLAYER
            #if UNITY_EDITOR
            if (PlayerPrefs.HasKey(axisName + "_AxisName") == false)
            {
                Debug.LogWarning("Missing key " + axisName + "_AxisName");
            }
            if (PlayerPrefs.HasKey(axisName + "_Speed") == false)
            {
                Debug.LogWarning("Missing key " + axisName + "_Speed");
            }
            if (PlayerPrefs.HasKey(axisName + "_Reset") == false)
            {
                Debug.LogWarning("Missing key " + axisName + "_Reset");
            }
            if (PlayerPrefs.HasKey(axisName + "_DeviceType") == false)
            {
                Debug.LogWarning("Missing key " + axisName + "_DeviceType");
            }
            if (PlayerPrefs.HasKey(axisName + "_Player") == false)
            {
                Debug.LogWarning("Missing key " + axisName + "_Player");
            }
            if (PlayerPrefs.HasKey(axisName + "_p_input") == false)
            {
                Debug.LogWarning("Missing key " + axisName + "_p_input");
            }
            if (PlayerPrefs.HasKey(axisName + "_p_modifier") == false)
            {
                Debug.LogWarning("Missing key " + axisName + "_p_modifier");
            }
            if (PlayerPrefs.HasKey(axisName + "_n_input") == false)
            {
                Debug.LogWarning("Missing key " + axisName + "_n_input");
            }
            if (PlayerPrefs.HasKey(axisName + "_n_modifier") == false)
            {
                Debug.LogWarning("Missing key " + axisName + "_n_modifier");
            }
            #endif
            axisName = PlayerPrefs.GetString(axisName + "_AxisName");
            m_Speed = PlayerPrefs.GetFloat(axisName + "_Speed");
            m_ResetOnRelease = Convert.ToBoolean(PlayerPrefs.GetInt(axisName + "_Reset"));
            m_DeviceType = (InputDevice)PlayerPrefs.GetInt(axisName + "_DeviceType");
            m_Player = (InputPlayer)PlayerPrefs.GetInt(axisName + "_Player");

            m_PositiveKey.input = PlayerPrefs.GetString(axisName + "_p_input");
            m_PositiveKey.modifier = (KeyCode)PlayerPrefs.GetInt(axisName + "_p_modifier");

            m_NegativeKey.input = PlayerPrefs.GetString(axisName + "_n_input");
            m_NegativeKey.modifier = (KeyCode)PlayerPrefs.GetInt(axisName + "_n_modifier");
            #else
            axisName = getData<string>("AxisName");
            m_Speed = getData<float>("Speed");
            m_ResetOnRelease = getData<bool>("Reset");
            m_DeviceType = (InputDevice)getData<int>("DeviceType");
            m_Player = (InputPlayer)getData<int>("Player");

            m_PositiveKey.input = getData<string>("p_input");
            m_PositiveKey.modifier = (KeyCode)getData<int>("p_modifier");

            m_NegativeKey.input = getData<string>("n_input");
            m_NegativeKey.modifier = (KeyCode)getData<int>("n_modifier");
            #endif
        }
Exemplo n.º 3
0
 public InputAxis()
 {
     m_PositiveKey = new InputKey(this, true);
     m_NegativeKey = new InputKey(this, false);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Returns true where the input string was successfully parsed.
        /// Returns false where the input string was a bad string
        /// </summary>
        /// <param name="aKey">The key to parse</param>
        /// <returns></returns>
        public static bool parseInputString(InputKey aKey)
        {
            if (aKey == null || aKey.owner == null)
            {
                return false;
            }
            //Make the string lower case
            string aInputString = aKey.input.ToLower();
            InputDevice aDeviceType = aKey.owner.deviceType;
            //Begin Parsing
            switch (aDeviceType)
            {
                case InputDevice.KEYBOARD:
                    {

                        if (aInputString == SPACE)
                        {
                            aKey.setAsKeyCode(KeyCode.Space);
                            return true;
                        }
                        else if (aInputString == LEFT_CONTROL)
                        {
                            aKey.setAsKeyCode(KeyCode.LeftControl);
                            return true;
                        }
                        else if (aInputString == LEFT_SHIFT)
                        {
                            aKey.setAsKeyCode(KeyCode.LeftShift);
                            return true;
                        }
                        else if (aInputString == LEFT_ALT)
                        {
                            aKey.setAsKeyCode(KeyCode.LeftAlt);
                            return true;
                        }
                        else if (aInputString == TAB)
                        {
                            aKey.setAsKeyCode(KeyCode.Tab);
                            return true;
                        }
                        else if (aInputString == ESC)
                        {
                            aKey.setAsKeyCode(KeyCode.Escape);
                            return true;
                        }
                        else if (aInputString == LEFT_ARROW)
                        {
                            aKey.setAsKeyCode(KeyCode.LeftArrow);
                            return true;
                        }
                        else if (aInputString == RIGHT_ARROW)
                        {
                            aKey.setAsKeyCode(KeyCode.RightArrow);
                            return true;
                        }
                        else if (aInputString == DOWN_ARROW)
                        {
                            aKey.setAsKeyCode(KeyCode.DownArrow);
                            return true;
                        }
                        else if (aInputString == UP_ARROW)
                        {
                            aKey.setAsKeyCode(KeyCode.UpArrow);
                            return true;
                        }
                        if (aInputString.Length > 0)
                        {
                            int keyID = aInputString[0];
                            if ((keyID >= 33 && keyID < 65) || (keyID >= 91 && keyID < 127))
                            {
                                aKey.setAsKeyCode((KeyCode)keyID);
                                return true;
                            }
                        }
                    }
                    break;
                case InputDevice.MOUSE:
                    if (aInputString == MOUSE_LEFT_BUTTON)
                    {
                        aKey.setAsMouseButton(MouseButton.LEFT);
                        return true;
                    }
                    else if (aInputString == MOUSE_RIGHT_BUTTON)
                    {
                        aKey.setAsMouseButton(MouseButton.RIGHT);
                        return true;
                    }
                    else if (aInputString == MOUSE_MIDDLE_BUTTON)
                    {
                        aKey.setAsMouseButton(MouseButton.MIDDLE);
                        return true;
                    }
                    else if (aInputString == MOUSE_X)
                    {
                        aKey.setAsAxis(MOUSE_X);
                        return true;
                    }
                    else if (aInputString == MOUSE_Y)
                    {
                        aKey.setAsAxis(MOUSE_Y);
                        return true;
                    }
                    else if (aInputString == MOUSE_SCROLL_Y)
                    {
                        aKey.setAsAxis(MOUSE_SCROLL_Y);
                        return true;
                    }

                    break;

                case InputDevice.XBOX_CONTROLLER:
                    if (aInputString == LEFT_STICK_X)
                    {
                        aKey.setAsAxis(LEFT_STICK_X);
                        return true;
                    }
                    else if (aInputString == LEFT_STICK_Y)
                    {
                        aKey.setAsAxis(LEFT_STICK_Y);
                        return true;
                    }
                    else if (aInputString == RIGHT_STICK_X)
                    {
                        aKey.setAsAxis(RIGHT_STICK_X);
                        return true;
                    }
                    else if (aInputString == RIGHT_STICK_Y)
                    {
                        aKey.setAsAxis(RIGHT_STICK_Y);
                        return true;
                    }
                    else if (aInputString == D_PAD_X)
                    {
                        aKey.setAsAxis(D_PAD_X);
                        return true;
                    }
                    else if (aInputString == D_PAD_Y)
                    {
                        aKey.setAsAxis(D_PAD_Y);
                        return true;
                    }
                    else if (aInputString == LEFT_TRIGGER)
                    {
                        aKey.setAsAxis(LEFT_TRIGGER);
                        return true;
                    }
                    else if (aInputString == RIGHT_TRIGGER)
                    {
                        aKey.setAsAxis(RIGHT_TRIGGER);
                        return true;
                    }
                    else if (aInputString == A)
                    {
                        aKey.setAsKeyCode(getGamepadButton(aInputString, aKey.owner.player));
                        return true;
                    }
                    else if (aInputString == B)
                    {
                        aKey.setAsKeyCode(getGamepadButton(aInputString, aKey.owner.player));
                        return true;
                    }
                    else if (aInputString == X)
                    {
                        aKey.setAsKeyCode(getGamepadButton(aInputString, aKey.owner.player));
                        return true;
                    }
                    else if (aInputString == Y)
                    {
                        aKey.setAsKeyCode(getGamepadButton(aInputString, aKey.owner.player));
                        return true;
                    }
                    else if (aInputString == LEFT_SHOULDER)
                    {
                        aKey.setAsKeyCode(getGamepadButton(aInputString, aKey.owner.player));
                        return true;
                    }
                    else if (aInputString == RIGHT_SHOULDER)
                    {
                        aKey.setAsKeyCode(getGamepadButton(aInputString, aKey.owner.player));
                        return true;
                    }
                    else if (aInputString == LEFT_STICK_IN)
                    {
                        aKey.setAsKeyCode(getGamepadButton(aInputString, aKey.owner.player));
                        return true;
                    }
                    else if (aInputString == RIGHT_STICK_IN)
                    {
                        aKey.setAsKeyCode(getGamepadButton(aInputString, aKey.owner.player));
                        return true;
                    }
                    else if (aInputString == BACK)
                    {
                        aKey.setAsKeyCode(getGamepadButton(aInputString, aKey.owner.player));
                        return true;
                    }
                    else if (aInputString == START)
                    {
                        aKey.setAsKeyCode(getGamepadButton(aInputString, aKey.owner.player));
                        return true;
                    }
                    break;

                default:

                    break;
            }
            return false;
        }