Upgrade to Pro — share decks privately, control downloads, hide ads and more …

俺はUniRxで行く

vailKAKO
February 15, 2020

 俺はUniRxで行く

I choose the form of UniRx.

vailKAKO

February 15, 2020
Tweet

More Decks by vailKAKO

Other Decks in Programming

Transcript

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

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

    https://github.com/neuecc/UniRx (࠷ޙʹ঺հ͠·͢) • ࠓ͸جຊతʹUniTaskͱซ༻͞ΕΔ • UniTask͸Taskͷ࠷దԽ൛ • Task͸ඇಉظॲཧͱ͔ͦ͏͍͏ͷ • ඇಉظॲཧ͸௕͘ͳΔͷͰ͍͔ͭͲ͔͜Ͱ୭͔͕ ೉ͦ͠͏ʹݟ͑Δ͚Ͳ UniRx ͜Θ͘ͳ͍ ˎʮϓϧϓϧο ΅͘ѱ͍3FBDUJWF&YUFOTJPOT͡Όͳ͍Αɻ ˝
  3. 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͢Δ
  4. _clapSubject .Subscribe(x => { Debug.Log(x.ToString()); }); UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ

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

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

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

    .AddTo(this); } UniRx ͷ͔͍͔ͭͨ 1. ΠϕϯτΛൃߦ͢Δ 2. ΠϕϯτΛଞਓ΋ݟΕΔΑ͏ʹެ։͢Δ 3. ΠϕϯτΛUniTaskʹม׵͢Δ 4. UniTaskΛawait͢Δ ߪಡ
  8. 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ͷྫ
  9. 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ͷྫ
  10. 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ͷྫ
  11. 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ͷྫ
  12. 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
  13. 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&,"
  14. private async void Start() { await UniTask.DelayFrame(1); Debug.Log(“1ϑϨʔϜ଴ͬͨΑ!!!"); } UniRx

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

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

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