Skip to content

Commit 6168143

Browse files
committed
feat(DeviceFinder): add ability to get hand of controller
It's now possible to determine which hand the controller is for by calling a new method `DeviceFinder.GetControllerHand(controllerObject);` which can be useful for determining which controller is interacting with an object. It can be used for example like so in the `StartUsing` method of an interactable object: `DeviceFinder.GetControllerHand(usingObject);` This will determine which controller is being used to `Use` the obejct.
1 parent 0b01d8c commit 6168143

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Assets/SteamVR_Unity_Toolkit/Scripts/Helper/DeviceFinder.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ public static ControllerHand GetControllerHandType(string hand)
4949
}
5050
}
5151

52+
public static ControllerHand GetControllerHand(GameObject controller)
53+
{
54+
var controllerManager = GameObject.FindObjectOfType<SteamVR_ControllerManager>();
55+
56+
if (controllerManager && controller == controllerManager.left)
57+
{
58+
return ControllerHand.Left;
59+
}
60+
61+
if (controllerManager && controller == controllerManager.right)
62+
{
63+
return ControllerHand.Right;
64+
}
65+
66+
return ControllerHand.None;
67+
}
68+
5269
public static bool IsControllerOfHand(GameObject checkController, ControllerHand hand)
5370
{
5471
var controllerManager = GameObject.FindObjectOfType<SteamVR_ControllerManager>();

0 commit comments

Comments
 (0)