Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality. If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers. And always feel free to hit us up on Twitter @MxdRealityDev.

MixedReality Motion Controllers - Best practises?

Hi Finally found a quite clean way to get input from the Motion Controllers while using Unity.
Would be nice with even more tips about this and best practices.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.XR.WSA.Input;

public class MixedReality_MotionControllerHandler : MonoBehaviour
{
bool _graspToogle = false, _grasping = false;

public void OnEnable()
{
    InteractionManager.InteractionSourcePressed += InteractionManager_InteractionSourcePressed;
    InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated;
    InteractionManager.InteractionSourceReleased += InteractionManager_InteractionSourceReleased;
}

public void OnDisable()
{
    InteractionManager.InteractionSourcePressed -= InteractionManager_InteractionSourcePressed;
    InteractionManager.InteractionSourceUpdated -= InteractionManager_InteractionSourceUpdated;
    InteractionManager.InteractionSourceReleased -= InteractionManager_InteractionSourceReleased;
}

private void InteractionManager_InteractionSourcePressed(InteractionSourcePressedEventArgs obj)
{

    Vector2 _thumbstickPosition = obj.state.thumbstickPosition;

    switch (obj.pressType)
    {
        case InteractionSourcePressType.None:
            break;
        case InteractionSourcePressType.Select:
            break;
        case InteractionSourcePressType.Menu:
            break;
        case InteractionSourcePressType.Grasp:
            if(obj.state.source.handedness == InteractionSourceHandedness.Left) // if left hand is being used
            {
                _grasping = true;
                _graspToogle = !_graspToogle;
                GraspToogled(_graspToogle);
            }
            break;
        case InteractionSourcePressType.Touchpad:
            break;
        case InteractionSourcePressType.Thumbstick:
            break;
        default:
            break;
    }

}

private void InteractionManager_InteractionSourceReleased(InteractionSourceReleasedEventArgs obj)
{
    switch (obj.pressType)
    {
        case InteractionSourcePressType.None:
            break;
        case InteractionSourcePressType.Select:
            break;
        case InteractionSourcePressType.Menu:
            break;
        case InteractionSourcePressType.Grasp:
            if (obj.state.source.handedness == InteractionSourceHandedness.Left) // if left hand is being used
            {
                _grasping = false;
            }
            break;
        case InteractionSourcePressType.Touchpad:
            break;
        case InteractionSourcePressType.Thumbstick:
            break;
        default:
            break;
    }
}

private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj)
{
}

void GraspToogled(bool _graspToogle)
{
    if (_graspToogle)
    {

    }
    else
    {

    }
}
void Update ()
{
    if(_grasping)
    {
        //do something while we are grasping with left hand
    }

    //Position Rotation Unity way
    //Vector3 leftPosition = InputTracking.GetLocalPosition(XRNode.LeftHand); //LeftEye,RightEye,CenterEye,Head  ++ a bunch of positions
    //Quaternion leftRotation = InputTracking.GetLocalRotation(XRNode.LeftHand);


    //var interactionSourceState = InteractionManager.GetCurrentReading();

    //if (interactionSourceState.Length > 0)
    //{
    //    if (interactionSourceState[0].thumbstickPosition.x >= 0.1f)
    //    {
    //        Debug.text = "Left Stick moved Left";
    //    }
    //}
}

}

Sign In or Register to comment.