public float GetAxis(string name) { if (m_DisableInput) { return(0.0f); } if (m_AxisInputCommands.ContainsKey(name)) { AxisInputCommand inputCommand = m_AxisInputCommands[name]; float value = 0.0f; //Check buttons if (inputCommand.PositiveKeyCode != KeyCode.None && inputCommand.NegativeKeyCode != KeyCode.None) { if (Input.GetKey(inputCommand.PositiveKeyCode)) { value += 1.0f; } if (Input.GetKey(inputCommand.NegativeKeyCode)) { value -= 1.0f; } if (value != 0.0f) { return(value); } } if (inputCommand.PositiveButtonCode != ControllerButtonCode.None && inputCommand.NegativeButtonCode != ControllerButtonCode.None) { if (ControllerInput.GetButton(inputCommand.ControllerIndex, inputCommand.PositiveButtonCode)) { value += 1.0f; } if (ControllerInput.GetButton(inputCommand.ControllerIndex, inputCommand.NegativeButtonCode)) { value -= 1.0f; } if (value != 0.0f) { return(value); } } //Check controller axis if (inputCommand.AxisCode != ControllerAxisCode.None) { return(ControllerInput.GetAxis(inputCommand.ControllerIndex, inputCommand.AxisCode)); } return(0.0f); } Debug.Log("No axis with name: " + name + " was found!"); return(0.0f); }
public void BindAxis(string name, int controllerIndex, ControllerAxisCode axisCode) { if (m_AxisInputCommands.ContainsKey(name)) { AxisInputCommand inputCommand = m_AxisInputCommands[name]; inputCommand.ControllerIndex = controllerIndex; inputCommand.AxisCode = axisCode; return; } m_AxisInputCommands.Add(name, new AxisInputCommand(controllerIndex, KeyCode.None, KeyCode.None, axisCode, ControllerButtonCode.None, ControllerButtonCode.None)); }
public void BindAxis(string name, KeyCode positiveKeyCode, KeyCode negativeKeyCode) { if (m_AxisInputCommands.ContainsKey(name)) { AxisInputCommand inputCommand = m_AxisInputCommands[name]; inputCommand.PositiveKeyCode = positiveKeyCode; inputCommand.NegativeKeyCode = negativeKeyCode; return; } m_AxisInputCommands.Add(name, new AxisInputCommand(0, positiveKeyCode, negativeKeyCode, ControllerAxisCode.None, ControllerButtonCode.None, ControllerButtonCode.None)); }