Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
非エンジニアにも分かる 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
72
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
非エンジニアにも分かる 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
110
少人数の SDK 開発を支えるテストの話 / tests for small group development
ryuj
0
620
位置情報を用いたモバイルゲームが 気軽に作れる 3D リアルマップサービス 「AROW」について (実践編) / how to AROW practice at Gotanda.unity #11
ryuj
0
84
技術書のすゝめ / suggestion of technical book
ryuj
0
93
Other Decks in Programming
See All in Programming
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
220
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
360
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.7k
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.3k
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
1k
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
330
Performance Optimization With LLMs
xleitix
0
160
最近”作らせてる” ローカルAIアプリの話
akit37
0
480
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
270
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
830
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
Featured
See All Featured
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
570
Leo the Paperboy
mayatellez
10
2.4k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
KATA
mclloyd
PRO
35
16k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
580
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
450
Building an army of robots
kneath
307
47k
How to make the Groovebox
asonas
2
2.5k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
560
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
540
New Earth Scene 8
popppiees
4
2.7k
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 まとめ • 難しいけど便利、実装のシンプル化 • 便利だけど複雑になるリスク ⇒ 必ずしも使えば良いわけではない