Unity¤Ë´ØÏ¢¤¹¤ëµ­»ö¤Ç¤¹

¡¡UniRx ¤Î¹ØÆɽèÍý¤ÏÈóƱ´ü½èÍý¤Ç¤¢¤ë¤¿¤á¡¢ÊÑ¿ô¼«ÂΤò null ¤Ë¤·¤Æ¤âÄä»ß¤·¤Þ¤»¤ó¡£
ÌÀ¼¨Åª¤Ë¼êÆ°¤Ç Dispose ¤¹¤ë¤«¡¢¤¢¤ë¤¤¤Ï AddTo ¥á¥½¥Ã¥É¤òÍøÍѤ·¤Æ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ä¥¯¥é¥¹¤ÎÇË´þ¤Î¥¿¥¤¥ß¥ó¥°¤ÇÄä»ß¤¹¤ë¤è¤¦¤Ë¥»¥Ã¥È¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£

¡¡¤³¤³¤Ç¤Ï¡¢¥²¡¼¥à¤ÎÅÓÃæ(¥é¥ó¥é¥¤¥àÃæ)¤Ë¤ª¤±¤ë¹ØÆɤÎÄä»ß½èÍý¡¢¤ª¤è¤Ó¡¢ºÆ¹ØÆɤμÂÁõÎã¤òÄ󼨤·¤Þ¤¹¡£



¹ØÆɽèÍý¤ÎÄä»ß¤Ë¤Ä¤¤¤Æ

¹ØÆɽèÍý¤ÎÄä»ß¤ÎÀß·×


¡¡Start ¥á¥½¥Ã¥É¤Ê¤É¤òÍøÍѤ·¤Æ Subscribe ¤·¤Æ¤¤¤ë½èÍý¤Ë¤Ä¤¤¤Æ¡¢¥²¡¼¥àÆâ¤ÇÄä»ß¤µ¤»¤ë¾ì¹ç¤Ë¤Ï¡¢
¸½ºßÆ°¤¤¤Æ¤¤¤ë¹ØÆɽèÍý¤òÄä»ß¤·¤¿¤¤¥¿¥¤¥ß¥ó¥°¤Ç Dispose ¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£

¡¡À­¼Á¾å¡¢Subscribe ¤·¤Æ¤¤¤ëÊÑ¿ô¤ÎÃͤò null ¤Ë¤·¤¿¤È¤·¤Æ¤â¡¢Æ°¤¤¤Æ¤¤¤ë¹ØÆɤνèÍý¤ÏÄä»ß¤·¤Þ¤»¤ó¡£
¤³¤ì¤Ï UniRx ¤¬ÈóƱ´ü¤Ç¼Â¹Ô¤µ¤ì¤Æ¤¤¤ë½èÍý¤Ë¤Ê¤ë¤¿¤á¤Ç¤¢¤ê¡¢¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤¬ÇË´þ¤µ¤ì¤Æ¤â¹ØÆɤ¬¼«Æ°Ää»ß¤·¤Ê¤¤¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤¿¤á¤Ç¤¹¡£
¤½¤Î¤¿¤á¡¢¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ÎÇË´þ¤Î¥¿¥¤¥ß¥ó¥°¤Ç¹ØÆɤòÄä»ß¤µ¤»¤ë AddTo ¥á¥½¥Ã¥É¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
¤Ê¤ª¡¢¥³¥ë¡¼¥Á¥ó¤Î½èÍý¤Î¾ì¹ç¤Ï¼«Æ°Åª¤Ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ÎÇË´þ¤Ëɳ¤Å¤¤¤Æ¤¤¤ë¤¿¤á¡¢ÈóƱ´ü½èÍý¤Ç¤Ï¤¢¤ê¤Þ¤¹¤¬¡¢¼«Æ°Åª¤ËÄä»ß¤·¤Þ¤¹¡£
¡¡

IDisposable ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹


¡¡AddTo ¥á¥½¥Ã¥É¤òÍøÍѤ»¤º(¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ä¥¯¥é¥¹¤òÇË´þ¤¹¤ë°Ê³°¤Î¥¿¥¤¥ß¥ó¥°¤Ç) Dispose ¤ò¼Â¹Ô¤¹¤ë¤¿¤á¤Ë¤Ï
IDisposable ·¿¤ÎÊÑ¿ô¤òÍÑ°Õ¤·¤Æ¤ª¤¤¤Æ¡¢¤½¤ÎÃæ¤Ë Subscribe ¤·¤Æ¤¤¤ë½èÍý¤òÂåÆþ¤·¤Æ¤ª¤­¤Þ¤¹¡£

¡¡¤³¤ì¤Ï¡¢Subscribe ¤ÎÌá¤êÃͤ¬ IDisposable ·¿¤Ç¤¢¤ë¤³¤È¤òÍøÍѤ·¤¿½èÍý¤Ë¤Ê¤ê¤Þ¤¹¡£

¡ãÎã¡ä
using System;
using UniRx;

public class TestDisposable {

    private IDisposable subscription;
    public ReactiveProperty<int> Hp = new(0);

    void Start() {
        subscription = Hp.Subscribe(value => Debug.Log(value));
    }
}



¡¡IDisposable ·¿¤Ï System ¤Î namespace ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Ç¤¹¡£
¤½¤Î¤¿¤á¡¢ÍøÍѤ¹¤ë¾ì¹ç¤Ë¤Ï using ¤Ç¤ÎÀë¸À¡¢¤¢¤ë¤¤¤Ï namespace ¤òÉÕ¤±¤¿·¿¤ÎÀë¸À¤¬É¬ÍפǤ¹¡£

¡ãusing ¤Ç¤ÎÀë¸À¡ä
  using System;

  IDisposable disposable;

¡ãnamespace ¤òÉÕ¤±¤¿·¿¤ÎÀë¸À¡ä
  private System.IDisposable disposable;



¡¡¤Þ¤¿ UniRx ¤Ë¤Ï¡¢IDisposable ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤ò¼ÂÁõ¤·¤Æ¤¤¤ë SingleAssigenmentDisposable ·¿¤â¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢¤½¤Á¤é¤âÍøÍѤǤ­¤Þ¤¹¡£
¤³¤Á¤é¤Ï UniRx ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë¤¿¤á¡¢System ¤ÎÀë¸ÀÉÔÍפÇÍøÍѤǤ­¤Þ¤¹¡£¥¯¥é¥¹¤Î¤¿¤á new ¤·¤Æ(¥¤¥ó¥¹¥¿¥ó¥¹¤òºîÀ®¤·¤Æ)ÍøÍѤ·¤Þ¤¹¡£

  private SingleAssignmentDisposable disposable = new();



¡¡¤³¤Î¤è¤¦¤Ë¤·¤Æ¡¢ Subscribe ¤ÎÌá¤êÃͤξðÊó(¹ØÆɤ·¤Æ¤¤¤ë½èÍý)¤òÂåÆþ¤·¤Æ¤ª¤¯¤¿¤á¤ÎÊÑ¿ô¤òÍÑ°Õ¤·¤Æ¤ª¤¯¤³¤È¤Ç¡¢
Ǥ°Õ¤Î¥¿¥¤¥ß¥ó¥°¤Ç¤³¤ÎÊÑ¿ô¤ò»È¤Ã¤Æ¡¢Subscribe ¤·¤Æ¤¤¤ë¹ØÆɽèÍý¤ò Dispose ¤·¡¢Ää»ß½ÐÍè¤Þ¤¹¡£

¡¡DOTween ¤âƱÍͤǤ¹¤¬¡¢°ìÅÙÆ°¤­½Ð¤·¤¿ÈóƱ´ü½èÍý¤Ë¤Ï¸å¤«¤é¼ê¤ò½Ð¤¹¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£
¤½¤Î¤¿¤á¡¢¥á¥½¥Ã¥É¼Â¹Ô»þ¤Ë¡¢½èÍý¼«ÂΤòÊÑ¿ô¤ËÂåÆþ¤·¤Æ¤ª¤¯É¬Íפ¬¤¢¤ê¤Þ¤¹¡£
¤³¤ÎÊÑ¿ôÆâ¤Ë¡¢¼Â¹Ô¤·¤Æ¤¤¤ëÈóƱ´ü½èÍý¤¬ÂåÆþ¤µ¤ì¤Æ¤¤¤ë¤Î¤Ç¡¢¤½¤ì¤ò¸å¤Ç»ß¤á¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£


»²¹Í¥µ¥¤¥È
Qiita @Marimoiro ÍÍ
UniRx¤Î¥·¥ó¥×¥ë¤Ê¥µ¥ó¥×¥ë ¤½¤Î6(¹ØÆɤÎÄä»ß)



ObservableEventTrigger ¤Ë¤ª¤±¤ë¼ÂÁõÎã

»öÁ°½àÈ÷


¡¡Canvas Æâ¤Ë Image ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÇÛÃÖ¡¢¤¢¤ë¤¤¤Ï¡¢Scene¥Ó¥å¡¼ Æâ¤Ë Cube ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ê¤É¤òÇÛÃÖ¤·¡¢
¤½¤ì¤Ë ObservableEventTrigger ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤ò¥¢¥¿¥Ã¥Á¤·¤Æ¤¯¤À¤µ¤¤¡£

¡¡¤É¤Á¤é¤òÍøÍѤ·¤Æ¤â¹½¤¤¤Þ¤»¤ó¡£

¡¡ºÇ½é¤Ë Canvas ¤ÎÊý¤ÎÎã¤òÄ󼨤·¤Æ¤ª¤­¤Þ¤¹¡£


¥Ò¥¨¥é¥ë¥­¡¼²èÁü




Image ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¡¡¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü




Game ¥Ó¥å¡¼




¡¡¤â¤¦£±¤ÄÎã¤È¤·¤Æ¡¢Scene¥Ó¥å¡¼ Æâ¤Ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÇÛÃÖ¤·¡¢¤³¤Á¤é¤òÍøÍѤ¹¤ë¥±¡¼¥¹¤Ç¤¹¡£
Ãí°ÕÅÀ¤È¤·¤Æ¤Ï¡¢¥Ò¥¨¥é¥ë¥­¡¼¤Ë EventSystem ¤¬É¬Íפʤ³¤È¤È¡¢MainCamera ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ë
Physics Raycaster ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¥¢¥¿¥Ã¥Á¤¬É¬ÍפˤʤëÅÀ¤Ç¤¹¡£
¡¡

¥Ò¥¨¥é¥ë¥­¡¼²èÁü




MainCamera ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¡¡¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü




Cube ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¡¡¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü




Game ¥Ó¥å¡¼




¥¹¥¯¥ê¥×¥È¤Î¼ÂÁõÎã


¡¡ºîÀ®¤·¤¿¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤ò¥Þ¥¦¥¹¤Ç¥¯¥ê¥Ã¥¯¤·¤¿ºÝ¤ËÈ¿±þ¤¹¤ë¤è¤¦¤Ë
ObservableEventTrigger ¤òÍøÍѤ·¡¢OnPointerDownAsObservable() ¤ò Subscribe ¤·¤Æ¹ØÆɤ·¤Þ¤¹¡£

¡¡Start ¥á¥½¥Ã¥É¤Ç Subscribe ¤·¤¿½èÍý¤Ë¤Ä¤¤¤Æ¡¢ÆÃÄê¤Î¥Ü¥¿¥ó¤ò²¡¤·¤¿¥¿¥¤¥ß¥ó¥°¤Ç¹ØÆɽèÍý¤òÄä»ß¤·¤Þ¤¹¡£
¤½¤Î¸å¡¢Ê̤νèÍý¤òºÆÅÙ¹ØÆɤµ¤»¤ë¤è¤¦¤Ë½èÍý¤ò¤Ä¤Ê¤²¤Þ¤¹¡£
¤Þ¤¿¡¢AddTo ¥á¥½¥Ã¥É¤ò¤Ä¤±¤Æ¤¤¤ë¤Î¤Ç¡¢¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤¬ÇË´þ¤µ¤ì¤¿¥¿¥¤¥ß¥ó¥°¤Ç¤â¹ØÆɽèÍý¤òÄä»ß¤Ç¤­¤Þ¤¹¡£


EventTriggerTest.cs

<= ¥¯¥ê¥Ã¥¯¤¹¤ë¤È³«¤­¤Þ¤¹


¡¡¥¹¥¯¥ê¥×¥È¤òºîÀ®¤·¤¿¤é¥»¡¼¥Ö¤·¤Þ¤¹¡£



¡¡Image ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¡¢¤¢¤ë¤¤¤Ï Cube ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ë EventTriggerTest ¥¹¥¯¥ê¥×¥È¤ò¥¢¥¿¥Ã¥Á¤·¤Þ¤¹¡£


Image ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¡¡¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü




Cube ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¡¡¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü



½èÍý¤ÎÀâÌÀ


¡¡Dispose ¤¹¤ë¤Þ¤Ç¤Î½èÍý¤Îή¤ì¡¢¤ª¤è¤Ó¡¢ºÆÅÙ¡¢¹ØÆɤνèÍý¤ò»Ï¤á¤ëºÝ¤Î½èÍý¤Ë¤Ä¤¤¤Æ¡¢½èÍý¤òÆɤ߲ò¤­¡¢Íý²ò¤ò¿¼¤á¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£

¡¡¤Þ¤¿¡¢System ¤Î IDisposable ¤òÍøÍѤ»¤º¡¢UniRx ¤Î¤ß¤ÇÄä»ß¤·¤¿¤¤¾ì¹ç¤Ë¤Ï¡¢
SingleAssignmentDisposable ·¿¤òÍøÍѤ¹¤ë¤³¤È¤Ç¤âÂåÍѲÄǽ¤Ç¤¹¡£


¡ãSystem.Disposable ¤ÎÂåÍѽèÍý¡ä
EventTriggerTest.cs

<= ¥¯¥ê¥Ã¥¯¤¹¤ë¤È³«¤­¤Þ¤¹¡£


¡¡ÊÑ¿ô¤ÎÀë¸À¤È½èÍý¤ÎÂåÆþÊýË¡¤¬ÊѤï¤ê¤Þ¤¹¤¬¡¢Î®¤ì¤ÏƱ¤¸¤Ç¤¹¡£
Ää»ßÌ¿Îá¤Ï IDisposable ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Î Dispose ¥á¥½¥Ã¥É¤ËÂФ·¤Æ¼Â¹Ô¤¹¤ë¤¿¤á¡¢Æ±¤¸Ì¿Îá½èÍý¤ÇÄä»ß½ÐÍè¤Þ¤¹¡£



¡¡UniRx¤Î¾ì¹ç¡¢Ê£¿ô¤Î¹ØÆɤνèÍý¤ò¤Þ¤È¤á¤ÆÄä»ß¤·¤¿¤¤¤È¤­¤Ë¤Ï¡¢IDisposable ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤ò¼ÂÁõ¤·¤Æ¤¤¤ë
CompositeDisposable ·¿¤òÍøÍѤ¹¤ë¤³¤È¤ÇÄä»ß¤µ¤»¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£

»²¹Í¥µ¥¤¥È
Qiita @yaegaki ÍÍ
UniRx ¹ØÆɤòÄä»ß¤¹¤ë




¼ÂÁõÆ°²è


¡¡Debug.Log ¥á¥½¥Ã¥É¤òÍøÍѤ·¡¢½èÍý¤¬Àµ¾ï¤ËÆ°ºî¤·¤Æ¤¤¤ë¤«¤ò³Îǧ¤·¤Þ¤¹¡£

¡¡Space ¥Ü¥¿¥ó¤ò²¡¤·¤¿¥¿¥¤¥ß¥ó¥°¤Ç¡¢ºÇ½é¤Ë¹ØÆɤ·¤Æ¤¤¤¿½èÍý¤¬Ää»ß¤·¡¢Âå¤ï¤ê¤ËÊ̤νèÍý¤¬¹ØÆɤµ¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£


¡ã³Îǧư²è­¡¡¡Image ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Î¥±¡¼¥¹¡ä
Æ°²è¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯


¡ã³Îǧư²è­¢¡¡Cube ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Î¥±¡¼¥¹¡ä
Æ°²è¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯


¡ãConsole ¥Ó¥å¡¼²èÁü¡ä




¡¡°Ê¾å¤Ë¤Ê¤ê¤Þ¤¹¡£
Subscribe ¤Ë¤è¤ë¹ØÆɽèÍý¤Ç¤¢¤ì¤Ð¡¢¹ØÆɸµ¤Ë¤Ê¤Ã¤Æ¤¤¤ë·¿¤Ï°ã¤Ã¤Æ¤â¡¢Æ±¤¸¤è¤¦¤ËÄä»ß¡¦ºÆ¹ÔÆ°¤µ¤»¤ë¤³¤È¤¬²Äǽ¤Ç¤¹¡£

¡¡±þÍÑÊýË¡¤ò¹Í¤¨¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£

¥³¥á¥ó¥È¤ò¤«¤¯


¡Öhttp://¡×¤ò´Þ¤àÅê¹Æ¤Ï¶Ø»ß¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

ÍøÍѵ¬Ìó¤ò¤´³Îǧ¤Î¤¦¤¨¤´µ­Æþ²¼¤µ¤¤

Menu


´ðÁÃ

µ»½Ñ/Ãμ±(¼ÂÁõÎã)

3D¥¢¥¯¥·¥ç¥ó¥²¡¼¥à

2D¤ª¤Ï¤¸¤­¥²¡¼¥à(ȯŸÊÔ)

2D¶¯À©²£¥¹¥¯¥í¡¼¥ë¥¢¥¯¥·¥ç¥ó(ȯŸÊÔ)

2D¥¿¥Ã¥×¥·¥å¡¼¥Æ¥£¥ó¥°(³ÈÄ¥ÊÔ)

¥ì¡¼¥¹¥²¡¼¥à(È´¿è)

2DÊüÃÖ¥²¡¼¥à(ȯŸÊÔ)

3D¥ì¡¼¥ë¥¬¥ó¥·¥å¡¼¥Æ¥£¥ó¥°(±þÍÑÊÔ)

3Dæ½Ð¥²¡¼¥à(È´¿è)

2D¥ê¥¢¥ë¥¿¥¤¥à¥¹¥È¥é¥Æ¥¸¡¼

3D¥¿¥Ã¥×¥¢¥¯¥·¥ç¥ó(NavMeshAgent »ÈÍÑ)

2D¥È¥Ã¥×¥Ó¥å¡¼¥¢¥¯¥·¥ç¥ó(¥«¥¨¥ë¤Î°Ù¤Ë¡Á¡¢¥Ü¥³¥¹¥«¥¦¥©¡¼¥ºÉ÷)

VideoPlayer ¥¤¥Ù¥ó¥ÈϢư¤Î¼ÂÁõÎã

VideoPlayer ¥ê¥¹¥ÈÆ⤫¤é¥à¡¼¥Ó¡¼ºÆÀ¸¤Î¼ÂÁõÎã(ȯŸ)

AR ²èÁüÉÕ¤­¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®¤Î¼ÂÁõÎã

AR ¥ê¥¹¥ÈÆ⤫¤éÀ¸À®¤Î¼ÂÁõÎã(ȯŸ)

2D¥È¥Ã¥×¥Ó¥å¡¼¥¢¥¯¥·¥ç¥ó(¥µ¥Ð¥¤¥Ð¡¼É÷)

private



¤³¤Î¥µ¥¤¥ÈÆâ¤ÎºîÉʤϥæ¥Ë¥Æ¥£¤Á¤ã¤ó¥é¥¤¥»¥ó¥¹¾ò¹à¤Î¸µ¤ËÄ󶡤µ¤ì¤Æ¤¤¤Þ¤¹¡£

´ÉÍý¿Í/Éû´ÉÍý¿Í¤Î¤ßÊÔ½¸¤Ç¤­¤Þ¤¹