WaveVR_ControllerManager

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

Contents

Introduction

WaveVR_ControllerManager tracks device(s) and shows / hides corresponding GameObject(s) if device(s) is tracked / lost-tracking.

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 RightCube to Dominant, LefCube to NonDominant.

_images/controllermanagertest02.png
  1. RightCube and LeftCube 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.

private void OnDeviceConnected(params object[] args)

Sample Code

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

The function SetDeviceIndex is unique and used to receive broadcasts.

After receiving a broadcast, the eDevice is updated.

public void SetDeviceIndex(WaveVR_Controller.EDeviceType device)
{
    Log.i (LOG_TAG, "SetDeviceIndex, _index = " + device);
    this.eDevice = device;
}

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

WVR_DeviceType _type = WaveVR_Controller.Input (this.eDevice).DeviceType;

Interop.WVR_GetPoseState (
    _type,
    WVR_PoseOriginModel.WVR_PoseOriginModel_OriginOnHead,
    500,
    ref pose);