WaveVR_ControllerManager

We do NOT encourage using this script since WaveVR_PoseTrackerManager provides more features.

Contents

Introduction

WaveVR_ControllerManager tracks a device and shows / hides the corresponding GameObject if the device is tracked / lost-tracking.

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

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

Function BroadcastToObjects sends a broadcast to SetDeviceIndex function in the 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 the sample scene ControllerManagerTest.
_images/controllermanagertest01.png
  1. Look in Inspector of CubeManager. The script WaveVR_Controller Manager is used here.

    Put RightCube to Dominant, LefCube to NonDominant.

_images/controllermanagertest02.png
  1. RightCube and LeftCube are used to demonstrate the usage of the 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 on an Android device. If the right / left controller is connected, the right / left cube 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 a device is connected, OnDeviceConnected will be called.

private void OnDeviceConnected(params object[] args)

Sample Code

The sample code ControllerManagerTest.cs shows how to get the pose of a 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 will be updated.

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

In Update, Interop.WVR_GetPoseState is called with _type to get the pose.

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

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