Skip to content

Instantly share code, notes, and snippets.

@demonixis
Created February 21, 2018 15:03
Show Gist options
  • Save demonixis/98b78c3eed7ee964de05edaaf1dd2336 to your computer and use it in GitHub Desktop.
Save demonixis/98b78c3eed7ee964de05edaaf1dd2336 to your computer and use it in GitHub Desktop.
An input driver for InControl using the 3DRudder controller.
using InControl;
using ns3DRudder;
using Unity3DRudder;
using UnityEngine;
namespace Demonixis.MarsExtraction.Inputs
{
public class RudderVirtualDevice : InputDevice
{
private Axis m_Axis;
private Rudder m_Rudder;
private ModeAxis m_ModeAxis;
private Vector2 m_LeftStickVector;
private Vector2 m_RightStickVector;
public RudderVirtualDevice()
: base("3DRudder Controller")
{
AddControl(InputControlType.LeftStickUp, "Left Stick Up");
AddControl(InputControlType.LeftStickDown, "Left Stick Down");
AddControl(InputControlType.LeftStickLeft, "Left Stick Left");
AddControl(InputControlType.LeftStickRight, "Left Stick Right");
AddControl(InputControlType.RightStickUp, "Right Stick Up");
AddControl(InputControlType.RightStickDown, "Right Stick Down");
AddControl(InputControlType.RightStickLeft, "Right Stick Left");
AddControl(InputControlType.RightStickRight, "Right Stick Right");
m_Axis = new Axis();
m_Rudder = s3DRudderManager.Instance.GetRudder(0);
m_ModeAxis = ModeAxis.NormalizedValue;
}
public override void Update(ulong updateTick, float deltaTime)
{
if (m_Rudder == null)
m_Rudder = s3DRudderManager.Instance.GetRudder(0);
if (m_Rudder == null)
return;
m_Axis = m_Rudder.GetAxis(m_ModeAxis);
m_LeftStickVector.x = m_Axis.GetXAxis();
m_LeftStickVector.y = m_Axis.GetYAxis();
m_RightStickVector.x = m_Axis.GetZRotation();
m_RightStickVector.y = m_Axis.GetZAxis();
UpdateLeftStickWithValue(m_LeftStickVector, updateTick, deltaTime);
UpdateRightStickWithRawValue(m_RightStickVector, updateTick, deltaTime);
Commit(updateTick, deltaTime);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment