- キーボード入力イベントの UniRx ラッパー
upm add package dev.upm-packages.unirx-observablekeyevent
Note: upm
command is provided by this repository.
You can also edit Packages/manifest.json
directly.
{
"dependencies": {
// (snip)
"dev.upm-packages.unirx-observablekeyevent": "[latest version]",
// (snip)
},
"scopedRegistries": [
{
"name": "Unofficial Unity Package Manager Registry",
"url": "https://upm-packages.dev",
"scopes": [
"dev.upm-packages"
]
}
]
}
npm install github:umm/unirx_observablekeyevent
using UniRx;
using UnityEngine;
public class Sample {
public void Hoge() {
ObservableKeyEvent.OnKeyAsObservable(KeyCode.A).Subscribe(_ => Debug.Log("A"));
ObservableKeyEvent.OnKeyDownAsObservable(KeyCode.B).Subscribe(_ => Debug.Log("B"));
ObservableKeyEvent.OnKeyUpAsObservable(KeyCode.C).Subscribe(_ => Debug.Log("C"));
}
}
- ストリームの Dispose などを自前で行う必要があります
using UniRx;
using UniRx.Triggers;
using UnityEngine;
public class Sample : MonoBehaviour {
private void Start() {
this.OnKeyAsObservable(KeyCode.A).Subscribe(_ => Debug.Log("A"));
this.OnKeyDownAsObservable(KeyCode.B).Subscribe(_ => Debug.Log("B"));
this.OnKeyUpAsObservable(KeyCode.C).Subscribe(_ => Debug.Log("C"));
}
}
- 該当のインスタンスが Destroy されると自動的に購読が Dispose されます
Copyright (c) 2018 Tetsuya Mori
Released under the MIT license, see LICENSE.txt