using System; using System.Text; namespace Framework.Input { /// Analogue axis on a joystick public struct JoystickAxis { /// Initializes a new joystick axis /// Name of the axis as set in Unity's input manager /// Whether to use the negative side of this axis public JoystickAxis(string axisName, bool isNegative) { this.AxisName = axisName; this.IsNegative = isNegative; } /// Name of the axis to use for the binding public string AxisName; /// Whether to use the negative side of this axis for the binding public bool IsNegative; /// Checks whether two joystick bindings are identical /// Binding that will be compared on the left side /// Binding that will be comapred on the right side /// True if the two bindings are identical public static bool operator ==(JoystickAxis left, JoystickAxis right) { return (left.AxisName == right.AxisName) && (left.IsNegative== right.IsNegative); } /// Checks whether two joystick bindings are not identical /// Binding that will be compared on the left side /// Binding that will be comapred on the right side /// True if the two bindings are not identical public static bool operator !=(JoystickAxis left, JoystickAxis right) { return (left.AxisName != right.AxisName) || (left.IsNegative!= right.IsNegative); } /// Obtains a hash code that is the same for identical instances /// The instance's hash code public override int GetHashCode() { return this.AxisName.GetHashCode() ^ this.IsNegative.GetHashCode(); } /// Checks whether another object is equal to this instance /// Other object that will be compared /// True if the other object is equal, false otherwise public override bool Equals(object otherObject) { if(otherObject is JoystickAxis) { var other = (JoystickAxis)otherObject; return (this.AxisName == other.AxisName) && (this.IsNegative== other.IsNegative); } else { return false; } } /// Returns a describing string for this instance /// A string describing the instance's identity public override string ToString() { var builder = new StringBuilder(18 + this.AxisName.Length); builder.Append("{Axis "); builder.Append(this.AxisName); if(this.IsNegative) { builder.Append(" (negative)}"); } else { builder.Append(" (positive)}"); } return builder.ToString(); } } } // namespace Framework.Input