mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-02-26 13:31:17 +03:00
SteamInput, Controller boilerplate
This commit is contained in:
parent
1ac22e1407
commit
ae1f648fa6
@ -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" />
|
||||
|
27
Facepunch.Steamworks.Test/InputTest.cs
Normal file
27
Facepunch.Steamworks.Test/InputTest.cs
Normal 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!" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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 @@ namespace Steamworks
|
||||
{
|
||||
_internal = new ISteamInput();
|
||||
_internal.Init();
|
||||
|
||||
_internal.DoInit();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
@ -26,6 +30,7 @@ namespace Steamworks
|
||||
|
||||
internal static void Shutdown()
|
||||
{
|
||||
_internal?.DoShutdown();
|
||||
_internal = null;
|
||||
}
|
||||
|
||||
@ -34,5 +39,23 @@ namespace Steamworks
|
||||
// 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] );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
14
Facepunch.Steamworks/Structs/Controller.cs
Normal file
14
Facepunch.Steamworks/Structs/Controller.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user