Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.
/ RxVRTK Public archive

Extensions for converting ALL the VRTK events to UniRx stream

License

Notifications You must be signed in to change notification settings

0V/RxVRTK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RxVRTK

Extensions for converting all the VRTK events to UniRx stream

Scripts are here.

For Release Notes and unitypackage, see RxVRTK/releases.

Dependencies

What is RxVRTK?

RxVRTK mediates VRTK (VR Toolkit) and UniRx.

RxVRTK consists of two components: Event extensions and RxVRTK components.

1. Event extensions

Event extensions provide extension methods to convert an exposed VRTK event such as VRTK_ControllerEvents.TriggerPressed to an Rx stream.

You can observe {EVENT NAME} by using {EVENT NAME}AsObservable() method.

Example: Event Extensions

// Add using directive
// using RxVRTK;

VRTK_ControllerEvents controllerEvents = GetComponent<VRTK_ControllerEvents>();

controllerEvents.TriggerPressedAsObservable()
    .Subscribe(_ =>
    {
        Debug.Log("Trigger Pressed!");
    });

Event extensions have a prefix "RxVRTK_" and a suffix "Extension".

2. RxVRTK components

RxVRTK components provide an event system that registers a callback by its method name and the registered callbacks are automatically called by the event system of VRTK.

An RxVRTK component inherits from VRTK classes and overrides the aforementioned methods so that it converts a VRTK event to Rx stream. When you use these components, you must not override such methods and must only use observable methods instead.

Note

Let's say you want to register a callback for "StartUsing". In this case, VRTK calls "StartUsing" of an VRTK_InteractableObject instance if it implements a method that matches the following signature:

void StartUsing(VRTK_InteractUse currentUsingObject);

As these methods are already overridden in RxVRTK_InteractableObject, which inherits VRTK_InteractableObject to fire UniRx events and RxVRTK utilizes this technique to register an event callback, ensure that you do not use neither "StartUsing" nor new to hide this method.

Example: RxVRTK components

The base class of RxVRTK_InteractableObject is VRTK_InteractableObject. This class provides interactive events: StartUsing, StartTouching, Grabbed, etc.

using RxVRTK;
using UniRx;
using UnityEngine;

public class SomeObject : RxVRTK_InteractableObject
{
    protected void Start()
    {
        this.StartUsingAsObservable()
            .Subscribe(user =>
            {
                Debug.Log(user.name + " is using this object!");
            });
    }
}

RxVRTK components have a prefix "RxVRTK_" but no suffix.

3. VRTK_UnityEvents<T>

VRTK_UnityEvents<T> uses UnityEvent<T>. UniRx has UnityEventExtensions which convert UnityEvent to Observable, so RxVRTK doesn't support UnityEvent. Please use UniRx.UnityEventExtensions.

Example: VRTK_UnityEvents<T>

AsObservable() is an extension method to convert UnityEvent to Observable.

// Add using directive
// using UniRx;

var controlEvents = GetComponent<VRTK_Control_UnityEvents>();
controlEvents.OnValueChanged.AsObservable()
    .Subscribe(e =>
    {
        Debug.Log("Changed: "+ e.Item2.value.ToString());
    });

License

This library is released under the MIT License.

About

Extensions for converting ALL the VRTK events to UniRx stream

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages