Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TakaakiIchijo/fa31b8163875184417e3b191c5f457ee to your computer and use it in GitHub Desktop.
Save TakaakiIchijo/fa31b8163875184417e3b191c5f457ee to your computer and use it in GitHub Desktop.
UnityInputSystemR3ObservableTriggerExtensions
using UnityEngine.InputSystem;
using R3;
namespace R3.Triggers
{
public static class InputSystemObservableTriggerExtensions
{
public static Observable<InputAction.CallbackContext> AsObservable(this InputAction action) =>
Observable.FromEvent<InputAction.CallbackContext>(
h =>
{
action.performed += h;
action.canceled += h;
},
h =>
{
action.performed -= h;
action.canceled -= h;
});
public static Observable<Unit> IsPressedAsObservable(this InputAction action) =>
Observable.EveryUpdate()
.Where(_ => action.IsPressed())
.Select(_ => Unit.Default);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment