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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Ryuichi Jinushi
March 31, 2021
Programming
66
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
97
少人数の SDK 開発を支えるテストの話 / tests for small group development
ryuj
0
590
位置情報を用いたモバイルゲームが 気軽に作れる 3D リアルマップサービス 「AROW」について (実践編) / how to AROW practice at Gotanda.unity #11
ryuj
0
73
技術書のすゝめ / suggestion of technical book
ryuj
0
85
Other Decks in Programming
See All in Programming
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
210
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
510
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
180
作るコストが小さくなった時代 幸せに働くために改めて考えたいこと 〜エンジニアとして価値を出し続けるために注視している二分野〜
yuppeeng
0
180
What's New in Android 2026
veronikapj
0
250
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
1
210
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
1
590
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
130
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
580
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
1.1k
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
1
1.3k
継続モナドとリアクティブプログラミング
yukikurage
3
680
Featured
See All Featured
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
980
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
330
Docker and Python
trallard
47
4.1k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
380
Building a Scalable Design System with Sketch
lauravandoore
463
34k
BBQ
matthewcrist
89
10k
Mobile First: as difficult as doing things right
swwweet
225
10k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
210
How to train your dragon (web standard)
notwaldorf
97
6.7k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
460
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 まとめ • 難しいけど便利、実装のシンプル化 • 便利だけど複雑になるリスク ⇒ 必ずしも使えば良いわけではない