/// <summary> /// Builds a string to get the controller by player. /// </summary> /// <param name="player"></param> /// <param name="axis"></param> /// <param name="type"></param> /// <param name="atype"></param> /// <returns></returns> public static string GetInput(OuyaSDK.OuyaPlayer player, AxisTypes axis, AnalogTypes atype) { Vector2 point; JoystickType joystickType = GetControllerType(player); switch (joystickType) { case JoystickType.ps3: //Note We don't care if the axis is X or Y, we just want to check for input from normalized. #region PS3 Controller point = new Vector2(Input.GetAxis(CheckInput(player, axis, JoystickType.ps3, AnalogTypes.Left)), Input.GetAxis(CheckInput(player, axis, JoystickType.ps3, AnalogTypes.Right))); if (point.x != 0f || point.y != 0f) { return(CheckInput(player, axis, JoystickType.ps3, atype)); } if (atype.Equals(AnalogTypes.DPad)) { return(CheckInput(player, axis, JoystickType.ps3, atype)); } #endregion return(string.Empty); case JoystickType.xbox: #region xbox360 point = new Vector2(Input.GetAxis(CheckInput(player, axis, JoystickType.xbox, AnalogTypes.Left)), Input.GetAxis(CheckInput(player, axis, JoystickType.xbox, AnalogTypes.Right))); if (point.x != 0f || point.y != 0f) { return(CheckInput(player, axis, JoystickType.xbox, atype)); } if (atype.Equals(AnalogTypes.DPad)) { return(CheckInput(player, axis, JoystickType.xbox, atype)); } if (atype.Equals(AnalogTypes.LTRT)) { return(CheckInput(player, axis, JoystickType.xbox, atype)); } #endregion return(string.Empty); case JoystickType.ouya: point = new Vector2(Input.GetAxis(CheckInput(player, axis, JoystickType.ouya, AnalogTypes.Left)), Input.GetAxis(CheckInput(player, axis, JoystickType.ouya, AnalogTypes.Right))); if (point.x != 0f || point.y != 0f) { return(CheckInput(player, axis, JoystickType.ouya, atype)); } if (atype.Equals(AnalogTypes.DPad)) { return(CheckInput(player, axis, JoystickType.ouya, atype)); } if (atype.Equals(AnalogTypes.LTRT)) { return(CheckInput(player, axis, JoystickType.ouya, atype)); } return(string.Empty); default: return("Horizontal"); } }
private static string findAnalogName(AnalogTypes type, ControllerPlayers player) { foreach (var map in AnalogMappings) { if (map.Type == type && map.Player == player) { return(map.Name); } } Debug.LogError(string.Format("Failed to find Analog {0} for Player {1}", type, player)); return("Unknown"); }
private static float processAnalogValue(AnalogTypes type, float value) { float tolerance = AnalogTolerance; switch (type) { case AnalogTypes.TriggerLeft: case AnalogTypes.TriggerRight: tolerance = AnalogTriggerTolerance; break; } return((Mathf.Abs(value) <= tolerance) ? 0 : value); }
/// <summary> /// This needs to be setup for each joystick type being supported. I have not setup the USB controller or the I:Droid:CON /// For the most part you won't need to modify this section. /// </summary> /// <param name="player"></param> /// <param name="axis"></param> /// <param name="joystick"></param> /// <param name="atype"></param> /// <returns></returns> private static string CheckInput(OuyaSDK.OuyaPlayer player, AxisTypes axis, JoystickType joystick, AnalogTypes atype) { //Debug.Log(string.Format("Player:{0} Axis:{1} Joystick:{2} AnalogType:{3}",player,axis,joystick,atype)); //REF: player1, DPadH, PS3, Dpad //Note: It is your responsibility to make sure that Unity Inputs are setup correctly or you will get an error on your controller. int axisNumber=0; switch (joystick) { case JoystickType.ps3: //Get The Joystick name from Project Settings --> Input for Controllers #region PS3 Controller if (atype.Equals(AnalogTypes.Left)) { ControllerType cType = OuyaControllerMapping.getController("ps3"); if (axis.Equals(AxisTypes.Horizontal)) { axisNumber = cType.leftAnalogH; } else { axisNumber = cType.leftAnalogV; } return "Joy" + (int)player + " Axis " + axisNumber.ToString(); } else if (atype.Equals(AnalogTypes.Right)) { ControllerType cType = OuyaControllerMapping.getController("ps3"); if (axis.Equals(AxisTypes.Horizontal)) { axisNumber = cType.rightAnalogH; } else { axisNumber = cType.rightAnalogV; } return "Joy" + (int)player + " Axis " + axisNumber.ToString(); } else if (atype.Equals(AnalogTypes.DPad)) { ControllerType cType = OuyaControllerMapping.getController("ps3"); if (axis.Equals(AxisTypes.DPadH)) { axisNumber = cType.dpadH; } else { axisNumber = cType.dpadV; } return "Joy" + (int)player + " Axis " + axisNumber.ToString(); } #endregion break; case JoystickType.xbox: #region xbox ( usually 360 / untested with normal xbox ) if (atype.Equals(AnalogTypes.Left)) { ControllerType cType = OuyaControllerMapping.getController("xbox360"); if (axis.Equals(AxisTypes.Horizontal)) { axisNumber = cType.leftAnalogH; } else { axisNumber = cType.leftAnalogV; } return "Joy" + (int)player + " Axis " + axisNumber.ToString(); } else if (atype.Equals(AnalogTypes.Right)) { ControllerType cType = OuyaControllerMapping.getController("xbox360"); if (axis.Equals(AxisTypes.Horizontal)) { axisNumber = cType.rightAnalogH; } else { axisNumber = cType.rightAnalogV; } return "Joy" + (int)player + " Axis " + axisNumber.ToString(); } else if (atype.Equals(AnalogTypes.DPad)) { ControllerType cType = OuyaControllerMapping.getController("xbox360"); if (axis.Equals(AxisTypes.DPadH)) { axisNumber = cType.dpadH; } else { axisNumber = cType.dpadV; } return "Joy" + (int)player + " Axis " + axisNumber.ToString(); } else if (atype.Equals(AnalogTypes.LTRT)) { ControllerType cType = OuyaControllerMapping.getController("xbox360"); axisNumber = cType.triggers; return "Joy" + (int)player + " Axis " + axisNumber.ToString(); } #endregion break; case JoystickType.ouya: #region OUYA - Not Tested until I get a bluetooth dongle if (atype.Equals(AnalogTypes.Left)) { ControllerType cType = OuyaControllerMapping.getController("ouya"); if (axis.Equals(AxisTypes.Horizontal)) { axisNumber = cType.leftAnalogH; } else { axisNumber = cType.leftAnalogV; } return "Joy" + (int)player + " Axis " + axisNumber.ToString(); } else if (atype.Equals(AnalogTypes.Right)) { ControllerType cType = OuyaControllerMapping.getController("ouya"); if (axis.Equals(AxisTypes.Horizontal)) { axisNumber = cType.rightAnalogH; } else { axisNumber = cType.rightAnalogV; } return "Joy" + (int)player + " Axis " + axisNumber.ToString(); } else if (atype.Equals(AnalogTypes.DPad)) { ControllerType cType = OuyaControllerMapping.getController("ouya"); if (axis.Equals(AxisTypes.DPadH)) { axisNumber = cType.dpadH; } else { axisNumber = cType.dpadV; } return "Joy" + (int)player + " Axis " + axisNumber.ToString(); } #endregion break; } //most likely we will never reach here, but If we do Return basic Horizontal Axis return "Horizontal"; }
/// <summary> /// Builds a string to get the controller by player. /// </summary> /// <param name="player"></param> /// <param name="axis"></param> /// <param name="type"></param> /// <param name="atype"></param> /// <returns></returns> public static string GetInput(OuyaSDK.OuyaPlayer player, AxisTypes axis, AnalogTypes atype) { Vector2 point; JoystickType joystickType = GetControllerType(player); switch (joystickType) { case JoystickType.ps3: //Note We don't care if the axis is X or Y, we just want to check for input from normalized. #region PS3 Controller point = new Vector2(Input.GetAxis(CheckInput(player, axis, JoystickType.ps3, AnalogTypes.Left)), Input.GetAxis(CheckInput(player, axis, JoystickType.ps3, AnalogTypes.Right))); if (point.x != 0f || point.y != 0f) { return CheckInput(player, axis, JoystickType.ps3, atype); } if (atype.Equals(AnalogTypes.DPad)){ return CheckInput(player, axis, JoystickType.ps3, atype); } #endregion return string.Empty; case JoystickType.xbox: #region xbox360 point = new Vector2(Input.GetAxis(CheckInput(player, axis, JoystickType.xbox, AnalogTypes.Left)), Input.GetAxis(CheckInput(player, axis, JoystickType.xbox, AnalogTypes.Right))); if (point.x != 0f || point.y != 0f) { return CheckInput(player, axis, JoystickType.xbox, atype); } if (atype.Equals(AnalogTypes.DPad)) { return CheckInput(player, axis, JoystickType.xbox, atype); } if (atype.Equals(AnalogTypes.LTRT)) { return CheckInput(player, axis, JoystickType.xbox, atype); } #endregion return string.Empty; case JoystickType.ouya: point = new Vector2(Input.GetAxis(CheckInput(player, axis, JoystickType.ouya, AnalogTypes.Left)), Input.GetAxis(CheckInput(player, axis, JoystickType.ouya, AnalogTypes.Right))); if (point.x != 0f || point.y != 0f) { return CheckInput(player, axis, JoystickType.ouya, atype); } if (atype.Equals(AnalogTypes.DPad)) { return CheckInput(player, axis, JoystickType.ouya, atype); } if (atype.Equals(AnalogTypes.LTRT)) { return CheckInput(player, axis, JoystickType.ouya, atype); } return string.Empty; default: return "Horizontal"; } }
/// <summary> /// This needs to be setup for each joystick type being supported. I have not setup the USB controller or the I:Droid:CON /// For the most part you won't need to modify this section. /// </summary> /// <param name="player"></param> /// <param name="axis"></param> /// <param name="joystick"></param> /// <param name="atype"></param> /// <returns></returns> private static string CheckInput(OuyaSDK.OuyaPlayer player, AxisTypes axis, JoystickType joystick, AnalogTypes atype) { //Debug.Log(string.Format("Player:{0} Axis:{1} Joystick:{2} AnalogType:{3}",player,axis,joystick,atype)); //REF: player1, DPadH, PS3, Dpad //Note: It is your responsibility to make sure that Unity Inputs are setup correctly or you will get an error on your controller. int axisNumber = 0; switch (joystick) { case JoystickType.ps3: //Get The Joystick name from Project Settings --> Input for Controllers #region PS3 Controller if (atype.Equals(AnalogTypes.Left)) { ControllerType cType = OuyaControllerMapping.getController("ps3"); if (axis.Equals(AxisTypes.Horizontal)) { axisNumber = cType.leftAnalogH; } else { axisNumber = cType.leftAnalogV; } return("Joy" + (int)player + " Axis " + axisNumber.ToString()); } else if (atype.Equals(AnalogTypes.Right)) { ControllerType cType = OuyaControllerMapping.getController("ps3"); if (axis.Equals(AxisTypes.Horizontal)) { axisNumber = cType.rightAnalogH; } else { axisNumber = cType.rightAnalogV; } return("Joy" + (int)player + " Axis " + axisNumber.ToString()); } else if (atype.Equals(AnalogTypes.DPad)) { ControllerType cType = OuyaControllerMapping.getController("ps3"); if (axis.Equals(AxisTypes.DPadH)) { axisNumber = cType.dpadH; } else { axisNumber = cType.dpadV; } return("Joy" + (int)player + " Axis " + axisNumber.ToString()); } #endregion break; case JoystickType.xbox: #region xbox ( usually 360 / untested with normal xbox ) if (atype.Equals(AnalogTypes.Left)) { ControllerType cType = OuyaControllerMapping.getController("xbox360"); if (axis.Equals(AxisTypes.Horizontal)) { axisNumber = cType.leftAnalogH; } else { axisNumber = cType.leftAnalogV; } return("Joy" + (int)player + " Axis " + axisNumber.ToString()); } else if (atype.Equals(AnalogTypes.Right)) { ControllerType cType = OuyaControllerMapping.getController("xbox360"); if (axis.Equals(AxisTypes.Horizontal)) { axisNumber = cType.rightAnalogH; } else { axisNumber = cType.rightAnalogV; } return("Joy" + (int)player + " Axis " + axisNumber.ToString()); } else if (atype.Equals(AnalogTypes.DPad)) { ControllerType cType = OuyaControllerMapping.getController("xbox360"); if (axis.Equals(AxisTypes.DPadH)) { axisNumber = cType.dpadH; } else { axisNumber = cType.dpadV; } return("Joy" + (int)player + " Axis " + axisNumber.ToString()); } else if (atype.Equals(AnalogTypes.LTRT)) { ControllerType cType = OuyaControllerMapping.getController("xbox360"); axisNumber = cType.triggers; return("Joy" + (int)player + " Axis " + axisNumber.ToString()); } #endregion break; case JoystickType.ouya: #region OUYA - Not Tested until I get a bluetooth dongle if (atype.Equals(AnalogTypes.Left)) { ControllerType cType = OuyaControllerMapping.getController("ouya"); if (axis.Equals(AxisTypes.Horizontal)) { axisNumber = cType.leftAnalogH; } else { axisNumber = cType.leftAnalogV; } return("Joy" + (int)player + " Axis " + axisNumber.ToString()); } else if (atype.Equals(AnalogTypes.Right)) { ControllerType cType = OuyaControllerMapping.getController("ouya"); if (axis.Equals(AxisTypes.Horizontal)) { axisNumber = cType.rightAnalogH; } else { axisNumber = cType.rightAnalogV; } return("Joy" + (int)player + " Axis " + axisNumber.ToString()); } else if (atype.Equals(AnalogTypes.DPad)) { ControllerType cType = OuyaControllerMapping.getController("ouya"); if (axis.Equals(AxisTypes.DPadH)) { axisNumber = cType.dpadH; } else { axisNumber = cType.dpadV; } return("Joy" + (int)player + " Axis " + axisNumber.ToString()); } #endregion break; } //most likely we will never reach here, but If we do Return basic Horizontal Axis return("Horizontal"); }
/// <summary> /// Gets the Analog Axis value with no tolerance /// </summary> /// <returns>The axis.</returns> /// <param name="type">Analog Type.</param> /// <param name="player">Player input accepted.</param> public static float GetAxisRaw(AnalogTypes type, ControllerPlayers player) { return(Input.GetAxisRaw(findAnalogName(type, player))); }
/// <summary> /// Initializes a new instance of the <see cref="Reign.InputExAnalogMap"/> class. /// </summary> /// <param name="type">Analog Type.</param> /// <param name="player">Player input accepted.</param> /// <param name="name">Button name defined in Unitys settings.</param> public InputExAnalogMap(AnalogTypes type, ControllerPlayers player, string name) { this.Type = type; this.Player = player; this.Name = name; }
/// <summary> /// Gets the Analog Axis value with no tolerance /// </summary> /// <returns>The axis.</returns> /// <param name="type">Analog Type.</param> /// <param name="player">Player input accepted.</param> public static float GetAxisRaw(AnalogTypes type, ControllerPlayers player) { return Input.GetAxisRaw(findAnalogName(type, player)); }
private static float processAnalogValue(AnalogTypes type, float value) { float tolerance = AnalogTolerance; switch (type) { case AnalogTypes.TriggerLeft: case AnalogTypes.TriggerRight: tolerance = AnalogTriggerTolerance; break; } return (Mathf.Abs(value) <= tolerance) ? 0 : value; }
private static string findAnalogName(AnalogTypes type, ControllerPlayers player) { foreach (var map in AnalogMappings) { if (map.Type == type && map.Player == player) { return map.Name; } } Debug.LogError(string.Format("Failed to find Analog {0} for Player {1}", type, player)); return "Unknown"; }
/// <summary> /// Initializes a new instance of the <see cref="Reign.InputExAnalogMap"/> class. /// </summary> /// <param name="type">Analog Type.</param> /// <param name="player">Player input accepted.</param> /// <param name="name">Button name defined in Unitys settings.</param> public InputExAnalogMap(AnalogTypes type, ControllerPlayers player, string name) { this.Type = type; this.Player = player; this.Name = name; }