WaveVR_ControllerManager

We do NOT encourage to use this script since WaveVR_PoseTrackermanager is a better choice.

Contents

Introduction

WaveVR_ControllerManager listens on tracked device(s).

Once a tracked device(s) is connected to a host, WaveVR_ControllerManager will broadcast the device index.

When WaveVR_ControllerManager receives event device_connected which is broadcasted from WaveVR.cs, it will check the device connection status in OnDeviceConnected.

Function BroadcastToObjects sends broadcast to SetDeviceIndex function in customized script of a specified GameObject.

Resources

Prefab WaveVR is located in Assets/WaveVR/Prefabs

Script WaveVR_ControllerManager.cs is located in Assets/WaveVR/Scripts

Sample scene ControllerManager_Test is located in Assets/Samples/ControllerManager_Test/Scenes

Sample script ControllerManagerTest.cs is located in Assets/Samples/ControllerManager_Test/Scripts

How to Use

  1. Open sample scene ControllerManagerTest.
_images/controllermanagertest01.png
  1. Look in Inspector of CubeManager. The script WaveVR_Controller Manager is used here.

    We put WVR_CONTROLLER_FINCH3DOF_1_0_MC_R to Right, WVR_CONTROLLER_FINCH3DOF_1_0_MC_L to Left.

_images/controllermanagertest02.png
  1. Developer can see the RightCube and LeftCube are gray out. They are used to demonstrate the usage of sample script ControllerManagerTest.cs.

    The sample script ControllerManagerTest.cs is used to receive the index from WaveVR_ControllerManager.

_images/controllermanagertest03.png _images/controllermanagertest04.png

Run this sample in Android device, if right / left controller is connected, right / left controller will be shown in scene.

Script

Listen / Remove WaveVR_Utils.Event.DEVICE_CONNECTED event in OnEnable / OnDisable

void OnEnable()
{
    WaveVR_Utils.Event.Listen(WaveVR_Utils.Event.DEVICE_CONNECTED, OnDeviceConnected);
}
void OnDisable()
{
    WaveVR_Utils.Event.Remove(WaveVR_Utils.Event.DEVICE_CONNECTED, OnDeviceConnected);
}

If device connected, OnDeviceConnected is called and get parameter WVR_DeviceType (arg[0]), bool (arg[1])

private void OnDeviceConnected(params object[] args)
{
    var device = (WVR_DeviceType)args[0];
    var connected = (bool)args[1];

Sample Code

The sample code ControllerManagerTest.cs shows how to get pose of device by using the deviceIndex broadcasted from WaveVR_ControllerManager.

The function SetDeviceIndex is unique and used to receive broadcasts.

After receiving a broadcast, the deviceIndex is updated.

public void SetDeviceIndex(WVR_DeviceType _index)
{
    Log.i (LOG_TAG, "SetDeviceIndex, _index = " + _index);
    deviceIndex = _index;
}

In Update, we call Interop.WVR_GetPoseState with deviceIndex to get the pose we want.

Interop.WVR_GetPoseState (
    deviceIndex,
    WVR_PoseOriginModel.WVR_PoseOriginModel_OriginOnGround,
    500,
    ref pose);