WaveVR API USAGE

Introduction

Developer can add code using wvr; to use WaveVR API (e.g. Interop.WVR_IsDeviceConnected )

There are information and restrictions about API usage.

Restriction

In WaveVR, there are some APIs can be called only once in a frame.

If those are called twice or more times in a frame, the result will be abnormal.

Do NOT use APIs listed below because those are already called by Unity engine SDK once in a frame:

  • WVR_GetSyncPose: to get device pose, use sample code
if (!Application.isEditor)
{
    if (WaveVR.Instance != null)
    {
        // Right controller
        WaveVR.Device _right = WaveVR.Instance.getDeviceByType(WVR_DeviceType.WVR_DeviceType_Controller_Right);
        // Left controller
        WaveVR.Device _left = WaveVR.Instance.getDeviceByType(WVR_DeviceType.WVR_DeviceType_Controller_Left);

        // Set to right pose
        gameObject.transform.localPosition = _right.rigidTransform.pos;
        gameObject.transform.localRotation = _right.rigidTransform.rot;

        // Set to left pose
        gameObject.transform.localPosition = _left.rigidTransform.pos;
        gameObject.transform.localRotation = _left.rigidTransform.rot;
    }
}
  • WVR_PollEventQueue: to receive system event, use sample code
void OnEnable()
{
    WaveVR_Utils.Event.Listen (WaveVR_Utils.Event.ALL_VREVENT, OnEvent);
}

void OnDisable()
{
    WaveVR_Utils.Event.Remove (WaveVR_Utils.Event.ALL_VREVENT, OnEvent);
}

void OnEvent(params object[] args)
{
    WVR_Event_t _event = (WVR_Event_t)args[0];
    switch (_event.common.type)
    {
            // Cases of event ...
    case WVR_EventType.WVR_EventType_ButtonPressed:
        break;
    case WVR_EventType.WVR_EventType_RecenterSuccess:
    case WVR_EventType.WVR_EventType_RecenterSuccess3DoF:
        break;
    }
}

Prerequisites

In WaveVR, there are some major APIs should be called before using other minor APIs.

Otherwise, those minor APIs does NOT take effect and may return false or null.

Please note major APIs list below:

WVR_SetInputRequest (new in SDK3.0.0)

Minor APIs:

  • WVR_GetInputTypeCount
  • WVR_GetInputDeviceState
  • WVR_GetInputButtonState
  • WVR_GetInputTouchState
  • WVR_GetInputAnalogAxis

Before using these minor APIs, WVR_SetInputRequest should be called first.

In WaveVR design, WVR_SetInputRequest is used in prefab WaveVRButtons , please refer to Buttons (new in SDK 3.0)

We don’t encourage developer to use WVR_SetInputRequest directly, please use WaveVRButtons instead to set up buttons.

Life Cycle

Unity application has life cycle, so developers need to check different conditions when using some APIs to get information if they don’t want to check at every frame (check in Update()).

E.g. Developers should consider following conditions when using WVR_GetInputMappingTable to get button mapping table:

private const uint inputTableSize = 10;
private WVR_InputMappingPair_t[] inputTable = new WVR_InputMappingPair_t[inputTableSize];

// Check mapping table in Start()
void Start()
{
    uint ucount = Interop.WVR_GetInputMappingTable (WVR_DeviceType.WVR_DeviceType_Controller_Right, this.inputTable, inputTableSize);
}

// Check mapping table when AP resumes.
void OnApplicationPause(bool pauseStatus)
{
    if (!pauseStatus)
    {
        uint ucount = Interop.WVR_GetInputMappingTable (WVR_DeviceType.WVR_DeviceType_Controller_Right, this.inputTable, inputTableSize);
    }
}

void OnEnable()
{
    WaveVR_Utils.Event.Listen (WaveVR_Utils.Event.ALL_VREVENT, OnEvent);
}

void OnDisable()
{
    WaveVR_Utils.Event.Remove (WaveVR_Utils.Event.ALL_VREVENT, OnEvent);
}

void OnEvent(params object[] args)
{
    WVR_Event_t _event = (WVR_Event_t)args[0];
    uint ucount = 0;
    switch (_event.common.type)
    {
    // Check mapping table after switching hand.
    case WVR_EventType.WVR_EventType_DeviceRoleChanged:
        ucount = Interop.WVR_GetInputMappingTable (WVR_DeviceType.WVR_DeviceType_Controller_Right, this.inputTable, inputTableSize);
        break;
    }
}