Skip to content

Instantly share code, notes, and snippets.

@julenka
Last active January 8, 2020 21:25
Show Gist options
  • Save julenka/c035834dec0dc66d80087ab6d07e1597 to your computer and use it in GitHub Desktop.
Save julenka/c035834dec0dc66d80087ab6d07e1597 to your computer and use it in GitHub Desktop.
Check if any hand is pinching or pressed in MRTK
// Approach using LINQ
private bool IsAnyHandPressed()
{
return CoreServices.InputSystem.DetectedControllers
.OfType<IMixedRealityHand>()
.Any(h => h.Interactions.Any(i => i.InputType == DeviceInputType.Select && i.BoolData));
}
// Approach using for loops
private bool IsAnyHandPressed()
{
foreach (var controller in CoreServices.InputSystem.DetectedControllers)
{
if (controller is IMixedRealityHand)
{
for (int i = 0; i < controller.Interactions.Length; i++)
{
if(controller.Interactions[i].InputType == DeviceInputType.Select && controller.Interactions[i].BoolData)
{
return true;
}
}
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment