SteamInput, Controller boilerplate

This commit is contained in:
Garry Newman 2019-06-19 13:08:49 +01:00
parent 1ac22e1407
commit ae1f648fa6
4 changed files with 65 additions and 0 deletions

View File

@ -97,6 +97,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="FriendsTest.cs" />
<Compile Include="InputTest.cs" />
<Compile Include="NetworkingSockets.cs" />
<Compile Include="SteamMatchmakingTest.cs" />
<Compile Include="RemoteStorageTest.cs" />

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Steamworks.Data;
namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
public class InputTest
{
[TestMethod]
public void ControllerList()
{
foreach ( var c in SteamInput.Controllers )
{
Console.WriteLine( "Got Contorller!" );
}
}
}
}

View File

@ -9,6 +9,8 @@ namespace Steamworks
{
public static class SteamInput
{
internal const int STEAM_CONTROLLER_MAX_COUNT = 16;
static ISteamInput _internal;
internal static ISteamInput Internal
{
@ -18,6 +20,8 @@ internal static ISteamInput Internal
{
_internal = new ISteamInput();
_internal.Init();
_internal.DoInit();
}
return _internal;
@ -26,6 +30,7 @@ internal static ISteamInput Internal
internal static void Shutdown()
{
_internal?.DoShutdown();
_internal = null;
}
@ -34,5 +39,23 @@ internal static void InstallEvents()
// None?
}
/// <summary>
/// Return a list of connected controllers. Will return null if none found.
/// </summary>
public static IEnumerable<Controller> Controllers
{
get
{
var array = new InputHandle_t[STEAM_CONTROLLER_MAX_COUNT];
var num = Internal.GetConnectedControllers( array );
for ( int i = 0; i < num; i++ )
{
yield return new Controller( array[num] );
}
}
}
}
}

View File

@ -0,0 +1,14 @@
using Steamworks.Data;
namespace Steamworks
{
public struct Controller
{
private InputHandle_t inputHandle;
internal Controller( InputHandle_t inputHandle_t )
{
this.inputHandle = inputHandle_t;
}
}
}