7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Unity の新しいInputSystemもAsObservableしたーい!

Last updated at Posted at 2020-02-25

拡張メソッド作った

    using UniRx;

    public static class UnityInputSystemExtensions

    {
        public static IObservable<InputAction.CallbackContext> AsObservable(this InputAction action)
        {
            return Observable.FromEvent<InputAction.CallbackContext>(
                h => action.performed += h,
                h => action.performed -= h);
        }
    }

使い方

var MainInput = new MainInput(); // ここは各環境によって違うと思う
MainInput.UI.Click.AsObservable().Subscribe(context => Debug.Log("clicked")).AddTo(this);
7
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?