Skip to content

Commit

Permalink
feat(SDK): allow configuration of controller simulator keys
Browse files Browse the repository at this point in the history
The SDK Simulator controller keys can now be configured via the
simulator camera rig prefab script. It is possible to redefine the
keys used to simulate the controller buttons within the Unity
inspector making it easier to customise.

The access to the raw SDK components in the SDK Bridge have also been
set to public, primarily so this feature can work, but it may also
be required by others if they want direct access to custom functions
on specific SDK components.
  • Loading branch information
thestonefox committed Jan 30, 2017
1 parent e6e063f commit 5ff229d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
37 changes: 36 additions & 1 deletion Assets/VRTK/SDK/Simulator/SDK_InputSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace VRTK
{
using UnityEngine;
using System.Collections.Generic;

/// <summary>
/// The `VRSimulatorCameraRig` prefab is a mock Camera Rig set up that can be used to develop with VRTK without the need for VR Hardware.
Expand Down Expand Up @@ -29,7 +30,7 @@ public class SDK_InputSimulator : MonoBehaviour
[Tooltip("Adjust player rotation speed.")]
public float playerRotationMultiplier = 0.5f;

[Header("Key bindings")]
[Header("Operation Key Bindings")]

[Tooltip("Key used to switch between left and righ hand.")]
public KeyCode changeHands = KeyCode.Tab;
Expand All @@ -40,6 +41,24 @@ public class SDK_InputSimulator : MonoBehaviour
[Tooltip("Key used to switch between X/Y and X/Z axis.")]
public KeyCode changeAxis = KeyCode.LeftControl;

[Header("Controller Key Bindings")]
[Tooltip("Key used to simulate trigger button.")]
public KeyCode triggerAlias = KeyCode.Mouse1;
[Tooltip("Key used to simulate grip button.")]
public KeyCode gripAlias = KeyCode.Mouse0;
[Tooltip("Key used to simulate touchpad button.")]
public KeyCode touchpadAlias = KeyCode.Q;
[Tooltip("Key used to simulate button one.")]
public KeyCode buttonOneAlias = KeyCode.E;
[Tooltip("Key used to simulate button two.")]
public KeyCode buttonTwoAlias = KeyCode.R;
[Tooltip("Key used to simulate start menu button.")]
public KeyCode startMenuAlias = KeyCode.F;
[Tooltip("Key used to switch between button touch and button press mode.")]
public KeyCode touchModifier = KeyCode.T;
[Tooltip("Key used to switch between hair touch mode.")]
public KeyCode hairTouchModifier = KeyCode.H;

#endregion
#region Private fields

Expand Down Expand Up @@ -89,6 +108,22 @@ private void Awake()
rightController.Selected = true;
leftController.Selected = false;
destroyed = false;

#if VRTK_SDK_SIM
Dictionary<string, KeyCode> keyMappings = new Dictionary<string, KeyCode>()
{
{"Trigger", triggerAlias },
{"Grip", gripAlias },
{"TouchpadPress", touchpadAlias },
{"ButtonOne", buttonOneAlias },
{"ButtonTwo", buttonTwoAlias },
{"StartMenu", startMenuAlias },
{"TouchModifier", touchModifier },
{"HairTouchModifier", hairTouchModifier }
};
SDK_SimController controllerSDK = (SDK_SimController)VRTK_SDK_Bridge.GetControllerSDK();
controllerSDK.SetKeyMappings(keyMappings);
#endif
}

private void OnDestroy()
Expand Down
5 changes: 5 additions & 0 deletions Assets/VRTK/SDK/Simulator/SDK_SimController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public class SDK_SimController : SDK_BaseController
protected const string RIGHT_HAND_CONTROLLER_NAME = "RightHand";
protected const string LEFT_HAND_CONTROLLER_NAME = "LeftHand";

public virtual void SetKeyMappings(Dictionary<string, KeyCode> givenKeyMappings)
{
keyMappings = givenKeyMappings;
}

/// <summary>
/// The ProcessUpdate method enables an SDK to run logic for every Unity Update
/// </summary>
Expand Down
8 changes: 4 additions & 4 deletions Assets/VRTK/SDK/VRTK_SDK_Bridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public static void ForceInterleavedReprojectionOn(bool force)
GetSystemSDK().ForceInterleavedReprojectionOn(force);
}

private static SDK_BaseSystem GetSystemSDK()
public static SDK_BaseSystem GetSystemSDK()
{
if (systemSDK == null)
{
Expand All @@ -436,7 +436,7 @@ private static SDK_BaseSystem GetSystemSDK()
return systemSDK;
}

private static SDK_BaseHeadset GetHeadsetSDK()
public static SDK_BaseHeadset GetHeadsetSDK()
{
if (headsetSDK == null)
{
Expand All @@ -445,7 +445,7 @@ private static SDK_BaseHeadset GetHeadsetSDK()
return headsetSDK;
}

private static SDK_BaseController GetControllerSDK()
public static SDK_BaseController GetControllerSDK()
{
if (controllerSDK == null)
{
Expand All @@ -454,7 +454,7 @@ private static SDK_BaseController GetControllerSDK()
return controllerSDK;
}

private static SDK_BaseBoundaries GetBoundariesSDK()
public static SDK_BaseBoundaries GetBoundariesSDK()
{
if (boundariesSDK == null)
{
Expand Down
8 changes: 8 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ Use the mouse and keyboard to move around both play area and hands and interacti
* **Hands On Off:** Key used to switch hands On/Off.
* **Rotation Position:** Key used to switch between positional and rotational movement.
* **Change Axis:** Key used to switch between X/Y and X/Z axis.
* **Trigger Alias:** Key used to simulate trigger button.
* **Grip Alias:** Key used to simulate grip button.
* **Touchpad Alias:** Key used to simulate touchpad button.
* **Button One Alias:** Key used to simulate button one.
* **Button Two Alias:** Key used to simulate button two.
* **Start Menu Alias:** Key used to simulate start menu button.
* **Touch Modifier:** Key used to switch between button touch and button press mode.
* **Hair Touch Modifier:** Key used to switch between hair touch mode.

### Class Methods

Expand Down

0 comments on commit 5ff229d

Please sign in to comment.