From ae1f648fa673813cf4703c1e0e7a16ce23bd7d9a Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Wed, 19 Jun 2019 13:08:49 +0100 Subject: [PATCH] SteamInput, Controller boilerplate --- .../Facepunch.Steamworks.Test.csproj | 1 + Facepunch.Steamworks.Test/InputTest.cs | 27 +++++++++++++++++++ Facepunch.Steamworks/SteamInput.cs | 23 ++++++++++++++++ Facepunch.Steamworks/Structs/Controller.cs | 14 ++++++++++ 4 files changed, 65 insertions(+) create mode 100644 Facepunch.Steamworks.Test/InputTest.cs create mode 100644 Facepunch.Steamworks/Structs/Controller.cs diff --git a/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj b/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj index 78cd6ce..9ce7c85 100644 --- a/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj +++ b/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj @@ -97,6 +97,7 @@ + diff --git a/Facepunch.Steamworks.Test/InputTest.cs b/Facepunch.Steamworks.Test/InputTest.cs new file mode 100644 index 0000000..8eef654 --- /dev/null +++ b/Facepunch.Steamworks.Test/InputTest.cs @@ -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!" ); + } + } + } + +} diff --git a/Facepunch.Steamworks/SteamInput.cs b/Facepunch.Steamworks/SteamInput.cs index c028da0..cd4e552 100644 --- a/Facepunch.Steamworks/SteamInput.cs +++ b/Facepunch.Steamworks/SteamInput.cs @@ -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? } + /// + /// Return a list of connected controllers. Will return null if none found. + /// + public static IEnumerable 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] ); + } + + } + } + } } \ No newline at end of file diff --git a/Facepunch.Steamworks/Structs/Controller.cs b/Facepunch.Steamworks/Structs/Controller.cs new file mode 100644 index 0000000..155edd3 --- /dev/null +++ b/Facepunch.Steamworks/Structs/Controller.cs @@ -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; + } + } +} \ No newline at end of file