Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
非エンジニアにも分かる UniRx(ゆにあーるえっくす)/ UniRx for non-eng...
Search
Ryuichi Jinushi
March 31, 2021
Programming
1
51
非エンジニアにも分かる UniRx(ゆにあーるえっくす)/ UniRx for non-engineers
UniRx(と言うか Rx)を非エンジニアの方にも伝わるように整理してみました。社内 LT 回で発表。
Ryuichi Jinushi
March 31, 2021
Tweet
Share
More Decks by Ryuichi Jinushi
See All by Ryuichi Jinushi
マップゲーム SDK 競合の話 / arow and other map game sdk
ryuj
0
940
マップゲーム SDK AROW とその運用を支える AWS の構成 / AROW with AWS
ryuj
0
89
少人数の SDK 開発を支えるテストの話 / tests for small group development
ryuj
0
460
位置情報を用いたモバイルゲームが 気軽に作れる 3D リアルマップサービス 「AROW」について (実践編) / how to AROW practice at Gotanda.unity #11
ryuj
0
63
技術書のすゝめ / suggestion of technical book
ryuj
0
75
Other Decks in Programming
See All in Programming
JSONataを使ってみよう Step Functionsが楽しくなる実践テクニック #devio2025
dafujii
1
520
Improving my own Ruby thereafter
sisshiki1969
1
160
go test -json そして testing.T.Attr / Kyoto.go #63
utgwkk
3
290
請來的 AI Agent 同事們在寫程式時,怎麼用 pytest 去除各種幻想與盲點
keitheis
0
120
ファインディ株式会社におけるMCP活用とサービス開発
starfish719
0
310
Namespace and Its Future
tagomoris
6
700
もうちょっといいRubyプロファイラを作りたい (2025)
osyoyu
1
420
Navigation 2 を 3 に移行する(予定)ためにやったこと
yokomii
0
140
旅行プランAIエージェント開発の裏側
ippo012
2
890
MCPでVibe Working。そして、結局はContext Eng(略)/ Working with Vibe on MCP And Context Eng
rkaga
5
2.2k
AIコーディングAgentとの向き合い方
eycjur
0
270
Processing Gem ベースの、2D レトロゲームエンジンの開発
tokujiros
2
120
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.7k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3k
Navigating Team Friction
lara
189
15k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
36
2.5k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
840
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
BBQ
matthewcrist
89
9.8k
It's Worth the Effort
3n
187
28k
What's in a price? How to price your products and services
michaelherold
246
12k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.9k
Documentation Writing (for coders)
carmenintech
74
5k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Transcript
非エンジニアにも分かる UniRx (ゆにあーるえっくす) じぬ
自己紹介
じぬしです
アジェンダ • とりあえず実例 • (Uni)Rx の概念 • ちゃんとした実用例
UniRx とは
Unity 向け Rx (リアクティブエクステンション) ライブラリ
Rx (リアクティブエクステンション) → タイミング制御などの難しい機能を 宣言的に実現できる表現方法 (非同期処理、イベント処理、時間処理)
Rx (リアクティブエクステンション) → タイミング制御などの難しい機能を 宣言的に実現できる表現方法 (非同期処理、イベント処理、時間処理) あんまり深く考えないでいいです
とりあえず実例
void Update() { // 毎フレーム実行される処理を書く }
void Update() { if (/* 右ボタンを押してるとき */) { /* キャラを右に少し動かす
*/ } }
// 最初に1回だけ実行される処理を書く void Start() { this.UpdateAsObservable() .Where(/* 右ボタン */) .Subscribe(/*
右へ動かす */); }
もうちょっと深掘りした実例
// 特徴:タイミングに関わる処理を書く void Update() { // 上ボタンが押されたらジャンプフラグを立てる } // 一定時間ごとに実行される処理を書く、特徴:物理演算系の処理を書く
void FixedUpdate() { // ジャンプフラグが立ってたら上向きの力を加える }
// 特徴:タイミングに関わる処理を書く void Update() { // 上ボタンが押されたらジャンプフラグを立てる } // 一定時間ごとに実行される処理を書く、特徴:物理演算系の処理を書く
void FixedUpdate() { // ジャンプフラグが立ってたら上向きの力を加える } • ジャンプという一つの機能だけなのに複 数箇所に記述が分かれる • ジャンプフラグを持つ必要がある
UniRx で置き換えると
void Start() { this.UpdateAsObservable() .Where(/* 上ボタンが押されたら */) .Subscribe(/* ジャンプフラグを立てる */);
this.FixedUpdateAsObservable() .Where(/* ジャンプフラグが立ってたら */) .Subscribe(/* 上向きの力を加える */); } • ジャンプという一つの機能だけなのに複 数箇所に記述が分かれる • ジャンプフラグを持つ必要がある
(Uni)Rx の概念
ストリーム
None
ストリーム 処理 1フレーム
1 2 3 4 5
1 2 3 4 5 専門的に言うと Observer パターン
Where ってなんだったの?
// 最初に1回だけ実行される処理を書く void Start() { this.UpdateAsObservable() .Where(/* 右ボタン */) .Subscribe(/*
右へ動かす */); }
Where ってなんだったの? ⇒ フィルタ
1 2 3 4 5 .Where(/* 奇数 */)
ちゃんとした実用例
// 連打対策(最初以外は一定時間無視) this.UpdateAsObservable() .Where(/* タップされた */) .ThrottleFirst(/* 1 秒 */)
.Subscribe(/* やりたい処理 */);
// 長押し this.UpdateAsObservable() .Where(/* 画面に触れた */) .Skip(/* 3 秒間スキップ */)
.First() .Subscribe(/* やりたい処理 */);
// Update, FixedUpdate の併用 var up = this.UpdateAsObservable() .Select(_ =>
Input.GetMouseButton(0)); // クリック状態 this.FixedUpdateAsObservable() .WithLatestFrom(up, (_, x) => x) // Update 時の検知を持ってくる .Where(x => x) // クリックされている時だけ .Subscribe(_ => Debug.Log("yes")); // やりたい処理
UniRx まとめ • 難しいけど便利、実装のシンプル化 • 便利だけど複雑になるリスク ⇒ 必ずしも使えば良いわけではない