File size: 6,054 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | #if (UNITY_STANDALONE || UNITY_EDITOR) && UNITY_ENABLE_STEAM_CONTROLLER_SUPPORT
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using UnityEngine.InputSystem.Utilities;
#if UNITY_EDITOR
using UnityEngine.InputSystem.Steam.Editor;
#endif
////TODO: support action set layers
namespace UnityEngine.InputSystem.Steam
{
/// <summary>
/// Base class for controllers made available through the Steam controller API.
/// </summary>
/// <remarks>
/// Unlike other controllers, the Steam controller is somewhat of an amorphous input
/// device which gains specific shape only in combination with an "In-Game Action File"
/// in VDF format installed alongside the application. These files specify the actions
/// that are supported by the application and are internally bound to specific controls
/// on a controller inside the Steam runtime. The bindings are set up in the Steam client
/// through its own binding UI.
///
/// Note that as the Steam controller API supports PS4 and Xbox controllers as well,
/// the actual hardware device behind a SteamController instance may not be a
/// Steam Controller. The <see cref="steamControllerType"/> property can be used what kind
/// of controller the Steam runtime is talking to internally.
///
/// This class is abstract. Specific Steam controller interfaces can either be implemented
/// manually based on this class or generated automatically from Steam IGA files using
/// <see cref="SteamIGAConverter"/>. This can be done in the editor by right-clicking
/// a .VDF file containing the actions and then selecting "Steam >> Generate Unity Input Device...".
/// The result is a newly generated device layout that will automatically register itself
/// with the input system and will represent a Steam controller with the specific action
/// sets and actions found in the .VDF file. The Steam handles for sets and actions will
/// automatically be exposed from the device and controls will be set up that correspond
/// to each action defined in the .VDF file.
///
/// Devices based on SteamController can be used in one of two ways.
///
/// The first method is by manually managing active action sets on a controller. This is done by
/// calling the various APIs (such as <see cref="ActivateSteamActionSet"/>) that correspond
/// to the methods in the <see cref="ISteamControllerAPI">Steam controller API</see>. The
/// controller handle is implicit in this case and corresponds to the <see cref="steamControllerHandle"/>
/// of the controller the methods are called on.
///
/// The second method is by using
///
///
///
///
///
/// By default, Steam controllers will automatically activate action set layers in
/// response to action maps being enabled and disabled. The correlation between Unity
/// actions and action maps and Steam actions and action sets happens entirely by name.
/// E.g. a Unity action map called "gameplay" will be looked up as a Steam action set
/// using the same name "gameplay".
/// </remarks>
public abstract class SteamController : InputDevice
{
internal const string kSteamInterface = "Steam";
/// <summary>
/// Handle in the <see cref="ISteamControllerAPI">Steam API</see> for the controller.
/// </summary>
public SteamHandle<SteamController> steamControllerHandle { get; internal set; }
/*
* TODO
public SteamControllerType steamControllerType
{
get { throw new NotImplementedException(); }
}*/
/// <summary>
/// The list of Steam action sets supported by this controller.
/// </summary>
/// <remarks>
/// Steam action sets are implicitly supplied to the Steam runtime rather than explicitly configured
/// by the application. ...
/// </remarks>
public abstract ReadOnlyArray<SteamActionSetInfo> steamActionSets { get; }
/// <summary>
/// Determine whether the controller automatically activates and deactivates action set
/// layers in response to <see cref="InputActionMap">input action map</see> being enabled
/// and disabled.
/// </summary>
/// <remarks>
/// This is on by default.
///
/// When on, if an <see cref="InputActionMap">action map</see> has bindings to a SteamController
/// and is enabled or disabled, the SteamController will automatically enable or disable
/// the correspondingly named Steam action set.
/// </remarks>
public bool autoActivateSets { get; set; }
protected SteamController()
{
autoActivateSets = true;
}
public void ActivateSteamActionSet(SteamHandle<InputActionMap> actionSet)
{
SteamSupport.GetAPIAndRequireItToBeSet().ActivateActionSet(steamControllerHandle, actionSet);
}
public SteamHandle<InputActionMap> currentSteamActionSet
{
get { return SteamSupport.GetAPIAndRequireItToBeSet().GetCurrentActionSet(steamControllerHandle); }
}
protected abstract void ResolveSteamActions(ISteamControllerAPI api);
protected abstract void Update(ISteamControllerAPI api);
// These methods avoid having an 'internal' modifier that every override needs to carry along.
internal void InvokeResolveSteamActions()
{
ResolveSteamActions(SteamSupport.GetAPIAndRequireItToBeSet());
}
internal void InvokeUpdate()
{
Update(SteamSupport.GetAPIAndRequireItToBeSet());
}
public struct SteamActionSetInfo
{
public string name { get; set; }
public SteamHandle<InputActionMap> handle { get; set; }
}
}
}
#endif // (UNITY_STANDALONE || UNITY_EDITOR) && UNITY_ENABLE_STEAM_CONTROLLER_SUPPORT
|