Pro Yearly is on sale from $80 to $50! »

俺はUniRxで行く

A6ba8150ec3d9e5f2c675ef8bd652ff5?s=47 vailKAKO
February 15, 2020

 俺はUniRxで行く

I choose the form of UniRx.

A6ba8150ec3d9e5f2c675ef8bd652ff5?s=128

vailKAKO

February 15, 2020
Tweet

Transcript

  1. Զ͸ ΨϯμϜ UniRxͰߦ͘ I choose the form of Gundam UniRx

    Speaker : Kako Time : about 9.5m
  2. Kakoɺ͓લ͸ͩΕͩ Ճݹ(26΋͏গ͠Ͱ27) ݽߴͷUnityઓ࢜(ϑϦʔϥϯε) ؔδϟχͷਪ͠͸ؙࢁ͘Μ ૔ෑ͔Βདྷͯ·͢

  3. ͜͏͍͏ͷΛָʹ΍Γ͍ͨ͜ͱͬͯ͋Γ·ͤΜ͔? ͳʹ͔͠ΒͷΞΫγϣϯͰɺ ঢ়گʹԠͯ͡ෳ਺ͷର৅͕ ֤ʑͷ൓ԠΛ͢Δ ͱ͜ΖͰ

  4. ͳʹ͔͠ΒͷΞΫγϣϯͰɺ ঢ়گʹԠͯ͡ෳ਺ͷର৅͕ ֤ʑͷ൓ԠΛ͢Δ Զ͸UniRx+UniTaskͰߦ͘

  5. UniRx is Կ • Reactive Extensions(Rx) ͷUnity޲͚C#ϥΠϒϥϦ • ඇಉظॲཧɺΠϕϯτॲཧ͕؆୯ʹͰ͖Δ •

    https://github.com/neuecc/UniRx (࠷ޙʹϦϯΫ͋Γ) • ࠓ͸جຊతʹUniTaskͱซ༻͞ΕΔ • UniTask͸Taskͷ࠷దԽ൛ • Task͸ඇಉظॲཧͱ͔ͦ͏͍͏ͷ • ඇಉظॲཧ͸௕͘ͳΔͷͰ͍͔ͭͲ͔͜Ͱ୭͔͕
  6. UniRx is Կ • Reactive Extensions(Rx) ͷUnity޲͚C#ϥΠϒϥϦ • ඇಉظॲཧɺΠϕϯτॲཧ͕؆୯ʹͰ͖Δ •

    https://github.com/neuecc/UniRx (࠷ޙʹ঺հ͠·͢) • ࠓ͸جຊతʹUniTaskͱซ༻͞ΕΔ • UniTask͸Taskͷ࠷దԽ൛ • Task͸ඇಉظॲཧͱ͔ͦ͏͍͏ͷ • ඇಉظॲཧ͸௕͘ͳΔͷͰ͍͔ͭͲ͔͜Ͱ୭͔͕ ೉ͦ͠͏ʹݟ͑Δ͚Ͳ UniRx ͜Θ͘ͳ͍ ˎʮϓϧϓϧο ΅͘ѱ͍3FBDUJWF&YUFOTJPOT͡Όͳ͍Αɻ ˝
  7. ࠓ೔͠Ό΂Δ͜ͱ 1. UniRxͷೖΕํ 2. Πϕϯτॲཧͱ͔ͷ࢖͍ํ • ΋ͬͱศརͳ࢖͍ํ͕େྔʹ͋Γ·͢ • UpdateΛݟ্͔͚͸ ͔͍ͭ·ͤΜ

    • UniTask͸ͪΐͬͱ͚ͩ΍Γ·͢ • interface੾Γ෼͚ɺDI͸؆୯ͷͨΊʹ΍Γ·ͤΜ
  8. ࠓ೔΍Δ͜ͱ ԻΛฉ͍ͯ……

  9. ࠓ೔΍Δ͜ͱ ى͖Δ

  10. 1.UniRxͷ͍Ε͔ͨ ~UniTask΋ͦ͑ͯ~

  11. UniRx ͱUniTaskͷ͍Ε͔ͨ 1. GitHub౳͔Βμ΢ϯϩʔυ 1. UnityPackageΛD&D 2. Ҏ্ 2. AssetStore͔Βimport

    1. Ҏ্
  12. 2.Πϕϯτॲཧͱ͔ͷ࢖͍ํ

  13. UniRx ͷ͔͍͔ͭͨ εΫϦϓτʹ࢖͏४උ using UniRx; using UniRx.Triggers; Using UniRx.Async;//͜ΕUniTask using

    UnityEngine;
  14. UniRx ͷ͔͍͔ͭͨΠϕϯτॲཧฤ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม׵͢Δ 4. UniTaskΛawait͢Δ

  15. 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͢Δ
  16. _clapSubject.Subscribe(x=>{}); _clapSubject.OnNext(_numOfClap); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม׵͢Δ

    4. UniTaskΛawait͢Δ ൃߦ ߪಡ
  17. _clapSubject .Subscribe(x => { Debug.Log(x.ToString()); }); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ

    2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม׵͢Δ 4. UniTaskΛawait͢Δ ߪಡ
  18. _clapSubject .Subscribe(x => { Debug.Log(x.ToString()); }); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ

    2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม׵͢Δ 4. UniTaskΛawait͢Δ ߪಡ
  19. _clapSubject .Subscribe(x => { Debug.Log(x.ToString()); }) .AddTo(this); UniRx ͷ͔͍͔ͭͨ 1.

    ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม׵͢Δ 4. UniTaskΛawait͢Δ ߪಡ
  20. private void Start() { _clapSubject .Subscribe(x => { Debug.Log(x.ToString()); })

    .AddTo(this); } UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม׵͢Δ 4. UniTaskΛawait͢Δ ߪಡ
  21. OnCollisionEnterAsObservable() OnBecameInvisibleAsObservable() OnMouseDownAsObservable() OnTriggerExit2DAsObservable() UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ

    3. ΠϕϯτΛUniTaskʹม׵͢Δ 4. UniTaskΛawait͢Δ ศརͳ5SJHHFSͷྫ UIJT 4VCTDSJCF  "EE5P UIJT 
  22. OnCollisionEnterAsObservable() OnBecameInvisibleAsObservable() OnMouseDownAsObservable() OnTriggerExit2DAsObservable() UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ

    3. ΠϕϯτΛUniTaskʹม׵͢Δ 4. UniTaskΛawait͢Δ ศརͳ5SJHHFSͷྫ
  23. 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ͷྫ
  24. 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ͷྫ
  25. 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ͷྫ
  26. 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ͷྫ
  27. 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
  28. 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&,"
  29. _clap.ClapAsObservable().ToUniTask(useFirstValue: true); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม׵͢Δ

    4. UniTaskΛawait͢Δ "OZ"OJNBM
  30. _clap.ClapAsObservable().ToUniTask(useFirstValue: true); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม׵͢Δ

    4. UniTaskΛawait͢Δ "OZ"OJNBM
  31. private async void Start() { await UniTask.DelayFrame(1); Debug.Log(“1ϑϨʔϜ଴ͬͨΑ!!!"); } UniRx

    ͷ͔͍͔ͭͨ Կ6OJ5BTLʜ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม׵͢Δ 4. UniTaskΛawait͢Δ
  32. private async void Start() { await _clap.ClapAsObservable()
 .ToUniTask(useFirstValue: true); Debug.Log("ى͖ͨΑ!");

    } UniRx ͷ͔͍͔ͭͨ (BNF0CKFDU"OZ"OJNBM 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม׵͢Δ 4. UniTaskΛawait͢Δ
  33. private async void Start() { await _clap.ClapAsObservable()
 .ToUniTask(useFirstValue: true); Debug.Log("ى͖ͨΑ!");

    } UniRx ͷ͔͍͔ͭͨ (BNF0CKFDU"OZ"OJNBM 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม׵͢Δ 4. UniTaskΛawait͢Δ
  34. 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͢Δ
  35. UniRx ͷ͔͍͔ͭͨΠϕϯτॲཧฤ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม׵͢Δ 4. UniTaskΛawait͢Δ

  36. ׬੒ͨ͠΋ͷ͕ͪ͜ΒͰ͢

  37. ·ͱΊ • 10෼(ϓϩδΣΫτ੍࡞30෼)Ͱࠓͷ͕Ͱ͖Δ • UniRx͜Θ͘ͳ͍ • UniTask΋ා͘ͳ͍ • Ͱ΋έʔεόΠέʔε

  38. ࢀߟ • ΋ͬͱͪΌΜͱ஌Γ͍ͨํ • https://qiita.com/toRisouP/items/3ced60a755ab297eb463#unirx---unitask • @toRisouP͞Μͷهࣄ(ܝࡌڐՄ͋Γ͕ͱ͏͍͟͝·͢) • UniRx •

    https://github.com/neuecc/UniRx • UniTask(UniRx.Async) • https://github.com/Cysharp/UniTask
  39. Thanks! RDAGさん作 むじさん作 ムッシュさん作 えんぺるさん作 阿宗さん作 アルコさん作 だー1さん作 志⿇ひぬこさん作

  40. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ RDAGさん作 むじさん作 ムッシュさん作 えんぺるさん作 阿宗さん作 アルコさん作 だー1さん作 志⿇ひぬこさん作