// Hopefully this layer on top of the existing functionality lets outside classes seamlessly change the axis. public void SetAxis(AxisOption axis) { axesToUse = axis; // Unregister existing axis stored so that we only register the desired choices. // Might cause problems when we test this, feel free to remove. CrossPlatformInputManager.UnRegisterVirtualAxis(horizontalAxisName); CrossPlatformInputManager.UnRegisterVirtualAxis(verticalAxisName); CreateVirtualAxes(); }
private float SnapFloat(float value, AxisOption snapAxis) { if (Math.Abs(value) < float.Epsilon) { return(value); } if (axesToUse == AxisOption.Both) { var angle = Vector2.Angle(_input, Vector2.up); if (snapAxis == AxisOption.OnlyHorizontal) { if (angle < 22.5f || angle > 157.5f) { return(0); } else { return((value > 0) ? 1 : -1); } } else if (snapAxis == AxisOption.OnlyVertical) { if (angle > 67.5f && angle < 112.5f) { return(0); } else { return((value > 0) ? 1 : -1); } } return(value); } else { if (value > 0) { return(1); } if (value < 0) { return(-1); } } return(0); }
private float GetRawInput(float value, AxisOption displaceAxis) { if (value == 0) { return(value); } var returnValue = value; if (_type == AxisOption.Both) { var angle = Vector2.Angle(Vector2.up, _input); if (displaceAxis == AxisOption.Horizontal) { if (angle < 25 || angle > 155) { returnValue = 0; } else { returnValue = value > 0 ? 1 : -1; } } if (displaceAxis == AxisOption.Vertical) { if (angle > 65 || angle < 115) { returnValue = 0; } else { returnValue = value > 0 ? 1 : -1; } } } else { returnValue = value > 0 ? 1 : -1; } return(returnValue); }