Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize Steam Input so it actually works #702

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Facepunch.Steamworks/SteamInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class SteamInput : SteamClientClass<SteamInput>
internal override bool InitializeInterface( bool server )
{
SetInterface( server, new ISteamInput( server ) );
Internal.Init( false );
if ( Interface.Self == IntPtr.Zero ) return false;

return true;
Expand Down
57 changes: 56 additions & 1 deletion Facepunch.Steamworks/Structs/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,61 @@ public AnalogState GetAnalogState( string actionName )
return SteamInput.Internal.GetAnalogActionData( Handle, SteamInput.GetAnalogActionHandle( actionName ) );
}

/// <summary>
/// Trigger a vibration event on supported controllers.
/// </summary>
/// <remarks>
/// <para>This API call will be ignored for incompatible controller models.</para>
/// <para>This generates the traditional "rumble" vibration effect.</para>
/// </remarks>
/// <param name="leftSpeed">The intensity value for the left rumble motor.</param>
/// <param name="rightSpeed">The intensity value of the right rumble motor.</param>
public void TriggerVibration( ushort leftSpeed, ushort rightSpeed )
{
SteamInput.Internal.TriggerVibration( Handle, leftSpeed, rightSpeed );
}

/// <summary>
/// Trigger a vibration event on supported controllers, including impulse trigger for Xbox One controllers.
/// <para>This API call will be ignored for incompatible controller models.</para>
/// <para>This generates the traditional "rumble" vibration effect.</para>
/// </summary>
/// <param name="leftSpeed">The intensity value for the left rumble motor.</param>
/// <param name="rightSpeed">The intensity value of the right rumble motor.</param>
/// <param name="leftTriggerSpeed">The intensity value of the Xbox One left trigger rumble</param>
/// <param name="rightTriggerSpeed">The intensity value of the Xbox One right trigger rumble.</param>
public void TriggerVibrationExtended( ushort leftSpeed, ushort rightSpeed, ushort leftTriggerSpeed, ushort rightTriggerSpeed )
{
SteamInput.Internal.TriggerVibrationExtended( Handle, leftSpeed, rightSpeed, leftTriggerSpeed, rightTriggerSpeed );
}

/// <summary>
/// Set the controller LED color on supported controllers.
/// </summary>
/// <param name="red">The red component of the color to set (0-255).</param>
/// <param name="green">The green component of the color to set (0-255).</param>
/// <param name="blue">The blue component of the color to set (0-255).</param>
public void SetLEDColor( byte red, byte green, byte blue )
{
SteamInput.Internal.SetLEDColor( Handle, red, green, blue, (uint)SteamControllerLEDFlag.SetColor );
}

/// <summary>
/// Set the controller LED color on supported controllers.
/// </summary>
/// <param name="color">Color to set the LED</param>
public void SetLEDColor( Color color )
{
SteamInput.Internal.SetLEDColor( Handle, color.r, color.g, color.b, (uint)SteamControllerLEDFlag.SetColor );
}

/// <summary>
/// Restore the controller LED color to default (out-of-game) settings
/// </summary>
public void RestoreUserLEDColor()
{
SteamInput.Internal.SetLEDColor( Handle, 0, 0, 0, (uint)SteamControllerLEDFlag.RestoreUserDefault );
}

public override string ToString() => $"{InputType}.{Handle.Value}";

Expand Down Expand Up @@ -94,4 +149,4 @@ public struct DigitalState
public bool Pressed => BState != 0;
public bool Active => BActive != 0;
}
}
}