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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Ryuichi Jinushi
March 31, 2021
Programming
64
1
Share
非エンジニアにも分かる UniRx(ゆにあーるえっくす)/ UniRx for non-engineers
UniRx(と言うか Rx)を非エンジニアの方にも伝わるように整理してみました。社内 LT 回で発表。
Ryuichi Jinushi
March 31, 2021
More Decks by Ryuichi Jinushi
See All by Ryuichi Jinushi
マップゲーム SDK 競合の話 / arow and other map game sdk
ryuj
0
1.1k
マップゲーム SDK AROW とその運用を支える AWS の構成 / AROW with AWS
ryuj
0
96
少人数の SDK 開発を支えるテストの話 / tests for small group development
ryuj
0
550
位置情報を用いたモバイルゲームが 気軽に作れる 3D リアルマップサービス 「AROW」について (実践編) / how to AROW practice at Gotanda.unity #11
ryuj
0
72
技術書のすゝめ / suggestion of technical book
ryuj
0
84
Other Decks in Programming
See All in Programming
検索設計から 推論設計への重心移動と Recall-First Retrieval
po3rin
5
1.6k
AIを導入する前にやるべきこと
negima
2
350
Lightning-Fast Method Calls with Ruby 4.1 ZJIT / RubyKaigi 2026
k0kubun
3
2.8k
Structured Concurrency, Scoped Values and Joiners in the JDK 25 26 27
josepaumard
1
150
[RubyKaigi 2026] Require Hooks
palkan
1
310
Back to the roots of date
jinroq
0
800
Agentic UI in the Frontend: Architectures with Open Standards @JAX 2026 in Mainz
manfredsteyer
PRO
0
110
How We Practice Exploratory Testing in Iterative Development( #scrumniigata ) / 反復開発の中で、探索的テストをどう実施しているか
teyamagu
PRO
3
790
Programming with a DJ Controller — not vibe coding
m_seki
3
820
JCON - Create Agentic AI Apps, The Easy Way!
kdubois
1
100
AIベース静的検査器の偽陽性率を抑える工夫3選
orgachem
PRO
4
450
20260514_its_the_context_window_stupid.pdf
heita
0
920
Featured
See All Featured
The browser strikes back
jonoalderson
0
1k
A better future with KSS
kneath
240
18k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
270
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
280
AI: The stuff that nobody shows you
jnunemaker
PRO
6
630
Navigating Team Friction
lara
192
16k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
390
Balancing Empowerment & Direction
lara
6
1.1k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
210
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.7k
What's in a price? How to price your products and services
michaelherold
247
13k
Amusing Abliteration
ianozsvald
1
160
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 まとめ • 難しいけど便利、実装のシンプル化 • 便利だけど複雑になるリスク ⇒ 必ずしも使えば良いわけではない