Skip to content

Instantly share code, notes, and snippets.

@ciwolsey
Last active August 8, 2019 05:33
Show Gist options
  • Save ciwolsey/5690259d59abb695871a367cd8f46a1a to your computer and use it in GitHub Desktop.
Save ciwolsey/5690259d59abb695871a367cd8f46a1a to your computer and use it in GitHub Desktop.
using Valve.VR;
using UnityEngine;
using UnityEngine.Events;
public class SteamVRBooleanAction : MonoBehaviour
{
public SteamVR_Action_Boolean InputAction;
public SteamVR_Input_Sources InputSource;
[System.Serializable]
public class Changed : UnityEvent<bool> {}
public Changed OutputAction;
private void Awake()
{
if (OutputAction == null)
OutputAction = new Changed();
}
private void OnEnable()
{
InputAction[InputSource].onChange += OnChange;
}
private void OnDisable()
{
InputAction[InputSource].onChange -= OnChange;
}
private void OnChange(SteamVR_Action_Boolean action, SteamVR_Input_Sources source, bool state)
{
OutputAction.Invoke(state);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment