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
71
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
100
少人数の SDK 開発を支えるテストの話 / tests for small group development
ryuj
0
600
位置情報を用いたモバイルゲームが 気軽に作れる 3D リアルマップサービス 「AROW」について (実践編) / how to AROW practice at Gotanda.unity #11
ryuj
0
77
技術書のすゝめ / suggestion of technical book
ryuj
0
92
Other Decks in Programming
See All in Programming
「人を評価する AI」の設計と実装
ryoyanara
0
260
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
250
Flow は今どうなっているか
mizdra
PRO
0
760
Hello, Hiroshima Geospatial Data! — Exploring DoboX with Python
ra0kley
0
120
レビュー履歴をAIに食わせて、 Compose移行を加速するs
shihochan
0
240
KotlinConf Extended South Korea 2026 Keynote
l2hyunwoo
0
120
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
400
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
160
Discordを用いたラボオートメーション関連情報収集の自動化
noguhiro2002
0
460
バグを直したら useEffect が消えた
colorful12
3
770
tsc.rip を支える技術 / Kyoto.なんか #8
susisu
0
3.8k
30年振りにコンパイラの定数整数除算を改善した
herumi
9
4.3k
Featured
See All Featured
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
260
30 Presentation Tips
portentint
PRO
1
380
Raft: Consensus for Rubyists
vanstee
141
7.7k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.5k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Everyday Curiosity
cassininazir
0
300
The Invisible Side of Design
smashingmag
301
52k
Paper Plane
katiecoart
PRO
2
53k
First, design no harm
axbom
PRO
2
1.3k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
670
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 まとめ • 難しいけど便利、実装のシンプル化 • 便利だけど複雑になるリスク ⇒ 必ずしも使えば良いわけではない