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で行く
Search
vailKAKO
February 15, 2020
Programming
0
52
俺はUniRxで行く
I choose the form of UniRx.
vailKAKO
February 15, 2020
Tweet
Share
More Decks by vailKAKO
See All by vailKAKO
俺はEditor拡張で行く ~ゼロから便利機能を作るまで
vailkako
0
400
Other Decks in Programming
See All in Programming
受け取る人から提供する人になるということ
little_rubyist
0
210
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
310
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.2k
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.3k
Java ジェネリクス入門 2024
nagise
0
700
Kaigi on Rails 2024 - Rails APIモードのためのシンプルで効果的なCSRF対策 / kaigionrails-2024-csrf
corocn
5
3.8k
Amazon Qを使ってIaCを触ろう!
maruto
0
380
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.3k
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
700
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
1
110
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
140
外部システム連携先が10を超えるシステムでのアーキテクチャ設計・実装事例
kiwasaki
1
280
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
693
190k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Six Lessons from altMBA
skipperchong
27
3.5k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
The Invisible Side of Design
smashingmag
297
50k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9k
Code Reviewing Like a Champion
maltzj
520
39k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Visualization
eitanlees
145
15k
Side Projects
sachag
452
42k
Building an army of robots
kneath
302
42k
Making Projects Easy
brettharned
115
5.9k
Transcript
Զ ΨϯμϜ UniRxͰߦ͘ I choose the form of Gundam UniRx
Speaker : Kako Time : about 9.5m
Kakoɺ͓લͩΕͩ Ճݹ(26͏গ͠Ͱ27) ݽߴͷUnityઓ࢜(ϑϦʔϥϯε) ؔδϟχͷਪؙ͠ࢁ͘Μ ෑ͔Βདྷͯ·͢
͜͏͍͏ͷΛָʹΓ͍ͨ͜ͱͬͯ͋Γ·ͤΜ͔? ͳʹ͔͠ΒͷΞΫγϣϯͰɺ ঢ়گʹԠͯ͡ෳͷର͕ ֤ʑͷԠΛ͢Δ ͱ͜ΖͰ
ͳʹ͔͠ΒͷΞΫγϣϯͰɺ ঢ়گʹԠͯ͡ෳͷର͕ ֤ʑͷԠΛ͢Δ ԶUniRx+UniTaskͰߦ͘
UniRx is Կ • Reactive Extensions(Rx) ͷUnity͚C#ϥΠϒϥϦ • ඇಉظॲཧɺΠϕϯτॲཧ͕؆୯ʹͰ͖Δ •
https://github.com/neuecc/UniRx (࠷ޙʹϦϯΫ͋Γ) • ࠓجຊతʹUniTaskͱซ༻͞ΕΔ • UniTaskTaskͷ࠷దԽ൛ • Taskඇಉظॲཧͱ͔ͦ͏͍͏ͷ • ඇಉظॲཧ͘ͳΔͷͰ͍͔ͭͲ͔͜Ͱ୭͔͕
UniRx is Կ • Reactive Extensions(Rx) ͷUnity͚C#ϥΠϒϥϦ • ඇಉظॲཧɺΠϕϯτॲཧ͕؆୯ʹͰ͖Δ •
https://github.com/neuecc/UniRx (࠷ޙʹհ͠·͢) • ࠓجຊతʹUniTaskͱซ༻͞ΕΔ • UniTaskTaskͷ࠷దԽ൛ • Taskඇಉظॲཧͱ͔ͦ͏͍͏ͷ • ඇಉظॲཧ͘ͳΔͷͰ͍͔ͭͲ͔͜Ͱ୭͔͕ ͦ͠͏ʹݟ͑Δ͚Ͳ UniRx ͜Θ͘ͳ͍ ˎʮϓϧϓϧο ΅͘ѱ͍3FBDUJWF&YUFOTJPOT͡Όͳ͍Αɻ ˝
ࠓ͠ΌΔ͜ͱ 1. UniRxͷೖΕํ 2. Πϕϯτॲཧͱ͔ͷ͍ํ • ͬͱศརͳ͍ํ͕େྔʹ͋Γ·͢ • UpdateΛݟ্͔͚ ͔͍ͭ·ͤΜ
• UniTaskͪΐͬͱ͚ͩΓ·͢ • interfaceΓ͚ɺDI؆୯ͷͨΊʹΓ·ͤΜ
ࠓΔ͜ͱ ԻΛฉ͍ͯ……
ࠓΔ͜ͱ ى͖Δ
1.UniRxͷ͍Ε͔ͨ ~UniTaskͦ͑ͯ~
UniRx ͱUniTaskͷ͍Ε͔ͨ 1. GitHub͔Βμϯϩʔυ 1. UnityPackageΛD&D 2. Ҏ্ 2. AssetStore͔Βimport
1. Ҏ্
2.Πϕϯτॲཧͱ͔ͷ͍ํ
UniRx ͷ͔͍͔ͭͨ εΫϦϓτʹ͏४උ using UniRx; using UniRx.Triggers; Using UniRx.Async;//͜ΕUniTask using
UnityEngine;
UniRx ͷ͔͍͔ͭͨΠϕϯτॲཧฤ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ
using System; using UniRx; using UniRx.Triggers; using UnityEngine; public class
ClapButton : MonoBehaviour { private Subject<int> _clapSubject = new Subject<int>(); private int _numOfClap = 0; } UniRx ͷ͔͍͔ͭͨ (BNF0CKFDU$MBQ#VUUPO 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ
_clapSubject.Subscribe(x=>{}); _clapSubject.OnNext(_numOfClap); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ
4. UniTaskΛawait͢Δ ൃߦ ߪಡ
_clapSubject .Subscribe(x => { Debug.Log(x.ToString()); }); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ
2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ ߪಡ
_clapSubject .Subscribe(x => { Debug.Log(x.ToString()); }); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ
2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ ߪಡ
_clapSubject .Subscribe(x => { Debug.Log(x.ToString()); }) .AddTo(this); UniRx ͷ͔͍͔ͭͨ 1.
ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ ߪಡ
private void Start() { _clapSubject .Subscribe(x => { Debug.Log(x.ToString()); })
.AddTo(this); } UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ ߪಡ
OnCollisionEnterAsObservable() OnBecameInvisibleAsObservable() OnMouseDownAsObservable() OnTriggerExit2DAsObservable() UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ
3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ ศརͳ5SJHHFSͷྫ UIJT 4VCTDSJCF "EE5P UIJT
OnCollisionEnterAsObservable() OnBecameInvisibleAsObservable() OnMouseDownAsObservable() OnTriggerExit2DAsObservable() UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ
3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ ศརͳ5SJHHFSͷྫ
this.OnMouseDownAsObservable().Subscribe(_ => { _numOfClap++; _clapSubject.OnNext(_numOfClap); MyAnimator.SetTrigger("Echo"); var etmp = Instantiate(echo);
etmp.SetActive(true); Destroy(etmp, 1); }).AddTo(_disposable); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ ศརͳ5SJHHFSͷྫ
this.OnMouseDownAsObservable().Subscribe(_ => { _numOfClap++; _clapSubject.OnNext(_numOfClap); MyAnimator.SetTrigger("Echo"); var etmp = Instantiate(echo);
etmp.SetActive(true); Destroy(etmp, 1); }).AddTo(_disposable); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ ศརͳ5SJHHFSͷྫ
this.OnMouseDownAsObservable().Subscribe(_ => { _numOfClap++; _clapSubject.OnNext(_numOfClap); MyAnimator.SetTrigger("Echo"); var etmp = Instantiate(echo);
etmp.SetActive(true); Destroy(etmp, 1); }).AddTo(_disposable); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ ศརͳ5SJHHFSͷྫ
this.OnMouseDownAsObservable().Subscribe(_ => { _numOfClap++; _clapSubject.OnNext(_numOfClap); MyAnimator.SetTrigger("Echo"); var etmp = Instantiate(echo);
etmp.SetActive(true); Destroy(etmp, 1); }).AddTo(_disposable); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ ศརͳ5SJHHFSͷྫ
using System; using UniRx; using UniRx.Triggers; using UnityEngine; public class
ClapButton : MonoBehaviour { public IObservable<int> ClapAsObservable() { return _clapSubject; } } UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ (BNF0CKFDU$MBQ#VUUPO
using System; using UniRx; using UniRx.Triggers; using UnityEngine; public class
HOKANODAREKA : MonoBehaviour { private ClapButton _clap => FindObjectOfType<ClapButton>(); private void Start() { _clap.ClapAsObservable().Subscribe(x =>{/*NANIKA*/}).AddTo(this); } } UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ )0,"/0%"3&,"
_clap.ClapAsObservable().ToUniTask(useFirstValue: true); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ
4. UniTaskΛawait͢Δ "OZ"OJNBM
_clap.ClapAsObservable().ToUniTask(useFirstValue: true); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ
4. UniTaskΛawait͢Δ "OZ"OJNBM
private async void Start() { await UniTask.DelayFrame(1); Debug.Log(“1ϑϨʔϜͬͨΑ!!!"); } UniRx
ͷ͔͍͔ͭͨ Կ6OJ5BTLʜ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ
private async void Start() { await _clap.ClapAsObservable() .ToUniTask(useFirstValue: true); Debug.Log("ى͖ͨΑ!");
} UniRx ͷ͔͍͔ͭͨ (BNF0CKFDU"OZ"OJNBM 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ
private async void Start() { await _clap.ClapAsObservable() .ToUniTask(useFirstValue: true); Debug.Log("ى͖ͨΑ!");
} UniRx ͷ͔͍͔ͭͨ (BNF0CKFDU"OZ"OJNBM 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ
private async void Start() { await _clap.ClapAsObservable() .SkipWhile(x => x
< sleepLevel) .ToUniTask(useFirstValue: true); Debug.Log(sleepLevel.ToString() + ”ճզຫͯ͠ى͖ͨΑ!”); } UniRx ͷ͔͍͔ͭͨ (BNF0CKFDU"OZ"OJNBM 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ
UniRx ͷ͔͍͔ͭͨΠϕϯτॲཧฤ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม͢Δ 4. UniTaskΛawait͢Δ
ͨ͠ͷ͕ͪ͜ΒͰ͢
·ͱΊ • 10(ϓϩδΣΫτ੍࡞30)Ͱࠓͷ͕Ͱ͖Δ • UniRx͜Θ͘ͳ͍ • UniTaskා͘ͳ͍ • ͰέʔεόΠέʔε
ࢀߟ • ͬͱͪΌΜͱΓ͍ͨํ • https://qiita.com/toRisouP/items/3ced60a755ab297eb463#unirx---unitask • @toRisouP͞Μͷهࣄ(ܝࡌڐՄ͋Γ͕ͱ͏͍͟͝·͢) • UniRx •
https://github.com/neuecc/UniRx • UniTask(UniRx.Async) • https://github.com/Cysharp/UniTask
Thanks! RDAGさん作 むじさん作 ムッシュさん作 えんぺるさん作 阿宗さん作 アルコさん作 だー1さん作 志⿇ひぬこさん作
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ RDAGさん作 むじさん作 ムッシュさん作 えんぺるさん作 阿宗さん作 アルコさん作 だー1さん作 志⿇ひぬこさん作