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

¡¡Á°²ó¤Î¼ê½ç¤Ë¤Ä¤Å¤­¡¢¥½¡¼¥¹¥³¡¼¥É¤Îµ­Ë¡³Ø½¬¤ò¹Ô¤¤¤Þ¤¹¡£

¡¡¥×¥í¥°¥é¥à¤Ë¤ª¤¤¤Æ¤Ï¡¢½èÍý¤Î·ë²Ì¤¬Æ±¤¸ÆâÍƤˤʤë¾ì¹ç¤Ç¤¢¤Ã¤Æ¤â¡¢µ­½Ò¤¹¤ë¥½¡¼¥¹¥³¡¼¥É¤ÎÆâÍƤ¬°Û¤Ê¤ë¥±¡¼¥¹¤¬¤¢¤ê¤Þ¤¹¡£
¤³¤³¤Ç¤Ï£±¤Ä¤ÎÌÜŪ(½èÍý¤Î·ë²Ì)¤ò¥Ù¡¼¥¹¤Ë¡¢°Û¤Ê¤ë¥½¡¼¥¹¥³¡¼¥É¤Îµ­Ë¡¤ò³Ø½¬¤·¤Þ¤¹¡£



ÌÜŪ


¡¡¥²¡¼¥àÆâ»þ´Ö¤ò·×¬¤·¡¢£±É䴤Ȥ˲èÌ̤Îɽ¼¨¤ò¹¹¿·¤¹¤ë

¡¡·×¬ÊýË¡¤Ë¤Ä¤¤¤Æ¤Ï³Ø½¬¤·¤Þ¤·¤¿¤Î¤Ç¡¢º£²ó¤Ï²èÌ̤Îɽ¼¨¤Ë¤Ä¤¤¤Æ¡¢ÍÍ¡¹¤Ê¥½¡¼¥¹¥³¡¼¥É¤Îµ­Ë¡¤ò¾Ò²ð¤·¤Þ¤¹¡£

¡¡¤¤¤º¤ì¤Îµ­Ë¡¤Ë¤ª¤¤¤Æ¤â¡¢½èÍýÆâ¤Ë¤Ï Debug.Log ¥á¥½¥Ã¥É¤òÍѤ¤¤Æ¡¢Console ¥Ó¥å¡¼¤Ë¤Æ»þ´Ö¤¬Àµ¾ï¤Ë·×¬¤Ç¤­¤Æ¤¤¤ë¤«¤ò³Îǧ¤·¤Þ¤¹¡£


¡ã¼Â¹Ô»þ¤Î½èÍý¤Î³Îǧ¡ä



¡¡³Æ¥½¡¼¥¹¥³¡¼¥É¤òµ­½Ò¤·¤¿¤é¡¢É¬¤º¥Ç¥Ð¥Ã¥°¤ò¹Ô¤¤¤Þ¤¹¡£
¾åµ­¤Î¤è¤¦¤Ë Console ¥Ó¥å¡¼¤Ë Debug.Log ¥á¥½¥Ã¥É¤Î¼Â¹Ô·ë²Ì¤¬É½¼¨¤µ¤ì¤ë¤³¤È¤ò³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£


µ­Ë¡£±¡¡¡¼°ìÈÌŪ¤ÊÊýË¡¡¼


¡¡¥á¥½¥Ã¥É¤Î°ú¿ô¤Ëɽ¼¨¤µ¤»¤¿¤¤»þ´Ö¤ÎÃͤò¼õ¤±¼è¤ê¡¢¤½¤ì¤òÉÁ²è¤·¤Þ¤¹¡£

  [SerializeField]
  private Text txtTime;

  public void UpdateDisplayTime(float time){
      txtTime.text = time.ToString("F2");
  }


µ­Ë¡£²¡¡¡¼DOTween ¤Î³èÍÑ¡¼

¡¡
¡¡DOTween ¤ÎÊä´Öµ¡Ç½¤ò³èÍѤ¹¤ë¤³¤È¤Ç¡¢²èÌÌɽ¼¨¤â¥¢¥Ë¥á¡¼¥·¥ç¥ó¤µ¤»¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£

¡¡int ·¿¤ÎÀ°¿ô(float ·¿¤ÎÉâÆ°¾®¿ô)¤Ë¤Ä¤¤¤Æ¤Ï Text.DOCounter() ¥á¥½¥Ã¥É¡¢DoVirtual.Float ¥á¥½¥Ã¥É¡¢
string ·¿¤Îʸ»úÎó¤Ë¤Ä¤¤¤Æ¤Ï Text.DOText() ¥á¥½¥Ã¥É¤¬ÍøÍѤǤ­¤Þ¤¹¡£

¡¡¤Ê¤ª TextMeshPro ¤Ë¤Ä¤¤¤Æ¤âƱ¥á¥½¥Ã¥É¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¤¬¡¢¤³¤Á¤é¤Ï DOTweenPro ¥¢¥»¥Ã¥È¤¬É¬Íפˤʤê¤Þ¤¹¡£
Text ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Ë¤Ä¤¤¤Æ¤Ï̵ÎÁ¥¢¥»¥Ã¥È¤ÇÍøÍѤǤ­¤Þ¤¹¡£

¡ãDOCounter(int ·¿¤ÎÀ°¿ô) ¥á¥½¥Ã¥É¡ä

  [SerializeField]
  private Text txtTime;

  [SerializeField]
  private Ease ease; 

¡¡private float oldTime;
  private float duration = 1.0f; 


  public void UpdateDisplayTime(int newTime){
      txtTime.DOCounter(oldTime, newTime, duration).SetEase(ease);
      oldTime = newTime;
  }

  public void UpdateDisplayTime(float newTime){
      txtTime.DOCounter((int)oldTime, (int)newTime, duration).SetEase(ease);
      oldTime = newTime;
  }

¡¡»þ´Ö¤Î¤è¤¦¤Ë¾®¿ô¤Ç´ÉÍý¤·¤Æ¤¤¤ëÃͤξì¹ç¤Ë¤Ï¡¢À°¿ô¤Ë¥­¥ã¥¹¥È¤·¤ÆÍøÍѤ·¤Þ¤¹¡£
¤¿¤À¤·¡¢Àµ³Î¤Ë¾®¿ôÅÀ¤ÎÃͤòɽ¼¨¤µ¤»¤¿¤¤¾ì¹ç¤Ë¤Ï¡¢¼¡¤Ë¾Ò²ð¤¹¤ë DOVirtual.Float ¥á¥½¥Ã¥É¤ò³èÍѤ·¤Æ¤¯¤À¤µ¤¤¡£

¡¡Ease ¤ÎÃͤòÊѹ¹¤¹¤ë¤³¤È¤Ç¡¢Êä´Ö¤Î¥¢¥Ë¥á¡¼¥·¥ç¥ó¤¬ÊѲ½¤·¤Þ¤¹¡£
¿§¡¹¤Ê¥Ñ¥¿¡¼¥ó¤ò³Îǧ¤·¤¿¤¤¾ì¹ç¤Ë¤Ï¡¢¥¹¥¯¥ê¥×¥ÈÆâ¤Ç Ease ¤ò»ØÄꤹ¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢
ÊÑ¿ô¤òÍÑ°Õ¤·¡¢¤½¤ì¤ò¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤«¤éÊѹ¹¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë¤³¤È¤Ç¥Ç¥Ð¥Ã¥°¤¬Íưפˤʤê¤Þ¤¹¡£


¡ãDOVirtual.Float(float ·¿¤ÎÉâÆ°¾®¿ô) ¥á¥½¥Ã¥É¡ä

  [SerializeField]
  private Text txtTime;

  [SerializeField]
  private Ease ease; 

¡¡private float oldTime;
  private float duration = 1.0f; 


  public void UpdateDisplayTime(float newTime){
      DOVirtual.Float(oldTime, newTime, duration, value => { txtTime.text = value.ToString("F2"); }).SetEase(ease);
      oldTime = value;
  }

¡¡¤Ê¤ª¡¢ÆâÉô·×»»¤ÏÉâÆ°¾®¿ô¤Ç¤¢¤Ã¤Æ¤â¡¢²èÌ̾å¤Ç¤ÏÀ°¿ôɽ¼¨¤µ¤»¤¿¤¤¾ì¹ç¤Ë¤Ï¡¢
ToString ¥á¥½¥Ã¥É ¤Î°ú¿ô¤ò "F0" ¤Ë»ØÄꤷ¤Æ¾®¿ôÅÀ¤ò¥«¥Ã¥È¤¹¤ëÊýË¡¤È¡¢value ¤ò int ·¿¤Ë¥­¥ã¥¹¥È¤¹¤ëÊýË¡¤¬¤¢¤ê¤Þ¤¹¡£


¡ãÀ°¿ôɽ¼¨¤ÎÎã¡ä
  // ToString ¥á¥½¥Ã¥É¤Î°ú¿ô¤òÊѹ¹¤·¤ÆÀ°¿ôɽ¼¨
  txtTime.text = value.ToString("F0");

¡¡// value ¤ò int ·¿¤Ë¥­¥ã¥¹¥È
  txtTime.text = (int)value.ToString();


¡ãDOText(string ·¿¤Îʸ»úÎó) ¥á¥½¥Ã¥É¡ä

  [SerializeField]
  private Text txtTime;

  private float duration = 1.0f; 


  public void UpdateDisplayMessage(string message){
      txtTime.DOText(message, duration).SetEase(Ease.Linear);
  }

¡¡Ê¸»ú¤ò°ìÄê¤Î®ÅÙ¤Çɽ¼¨¤µ¤»¤¿¤¤¾ì¹ç¤Ë¤Ï¡¢SetEase ¥á¥½¥Ã¥É¤ò Ease.Linear ¤Ç»ØÄꤹ¤ë¤³¤È¤Ç¡¢Åù®ɽ¼¨¤Ë¤Ê¤ê¤Þ¤¹¡£


µ­Ë¡£³¡¡¡¼MV(R)P ¥Ñ¥¿¡¼¥ó¤Î³èÍÑ¡¼


¡¡Model ¥¯¥é¥¹¤Ë¤ª¤¤¤Æ ReactiveProperty ¤òÍÑ°Õ¤·¡¢Presenter ¤Ë¤Æ¹ØÆɤ·¤Þ¤¹¡£

¡¡View ¥¯¥é¥¹¤Ë¤Ïµ­Ë¡£±¤ÈƱ¤¸¤è¤¦¤Ëµ­½Ò¤·¤Þ¤¹¡£



¡ãModel ¥¯¥é¥¹¡ä
¡¡using UniRx;

  public ReactiveProperty<int> Time = new();



¡ãView ¥¯¥é¥¹¡ä
  [SerializeField]
  private Text txtTime;

  public void UpdateDisplayTime(int time){
      txtTime.text = time.ToString();
  }



¡ãPresenter ¥¯¥é¥¹¡ä
¡¡using UniRx;

  [SerializeField]
  private Model model;

  [SerializeField]
  private View view;

  void Start() {
      model.Time.Subscribe(time => view.UpdateDisplayTime(time)).AddTo();
  }

¡¡»þ´Ö¤Î·×¬ÊýË¡¼«ÂΤϰÊÁ°¤Î¶µºà¤Ë¤Æ¾Ò²ðºÑ¤Ç¤¢¤ë¤¿¤á¡¢³ä°¦¤·¤Þ¤¹¡£


µ­Ë¡£´¡¡¡¼MV(R)P ¥Ñ¥¿¡¼¥ó¤È DOTween ¤ÎÁȤ߹ç¤ï¤»¡¼


¡¡UniRx ¤ËÍÑ°Õ¤µ¤ì¤Æ¤¤¤ë¥ª¥Ú¥ì¡¼¥¿¤Î¤¦¤Á¡¢ Zip() ¥á¥½¥Ã¥É¤È Skip() ¥á¥½¥Ã¥É¤ò³èÍѤ¹¤ë¤³¤È¤Ç¡¢
ReactiveProperty ¤Ç¹ØÆɤ·¤Æ¤¤¤ëÃͤò DOCounter() ¥á¥½¥Ã¥É¤òÍøÍѤ·¤Æ¥¢¥Ë¥áɽ¼¨¤µ¤»¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹¡£

¡¡¥ª¥Ú¥ì¡¼¥¿¤È¤Ï Subject ¤Ë¤è¤Ã¤Æ OnNext ¥á¥Ã¥»¡¼¥¸¤¬È¯¹Ô¤µ¤ì¤¿ºÝ¤Ë¡¢Subscribe ¤¹¤ëÁ°¤Ë¶´¤ß¹þ¤à¤³¤È¤¬¤Ç¤­¤ë½èÍý¤Î¤³¤È¤Ç¡¢UniRx ¤ËÍÑ°Õ¤µ¤ì¤Æ¤¤¤ë¥á¥½¥Ã¥É·²¤Ç¤¹¡£
¤¿¤¯¤µ¤ó¤Î¥ª¥Ú¥ì¡¼¥¿¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£Linq ¤Î¤è¤¦¤Ë¥á¥½¥Ã¥É¡¦¥Á¥§¡¼¥ó¤µ¤»¤ÆÊ£¿ô¤Î¥ª¥Ú¥ì¡¼¥¿¤ò¶´¤ß¤³¤ó¤Ç½èÍý¤Î¥í¥¸¥Ã¥¯¤ò¹½ÃۤǤ­¤Þ¤¹¡£

¡¡¥ª¥Ú¥ì¡¼¥¿¤Î¼ïÎà¤Ë¤Ä¤¤¤Æ¤Ï¡¢²¼µ­¤Î¥µ¥¤¥È¤Ë¾Ü¤·¤¯¤Þ¤È¤á¤é¤ì¤Æ¤¤¤ë¤Î¤Ç»²¹Í¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£

¡ã»²¹Í¥µ¥¤¥È¡ä
Qiita @toRisouP(³ô¼°²ñ¼Ò ¥Ð¡¼¥Á¥ã¥ë¥­¥ã¥¹¥È)
UniRx ¥ª¥Ú¥ì¡¼¥¿°ìÍ÷




¡¡µ­Ë¡£²(DOTween)¤Î View ¥¯¥é¥¹¤È¡¢µ­Ë¡£³(MV(R)P ¥Ñ¥¿¡¼¥ó) Presenter ¥¯¥é¥¹¤Î½èÍý¤ò½ñ¤­´¹¤¨¤ë¤³¤È¤Ç¼ÂÁõ½ÐÍè¤Þ¤¹¡£


¡ãView ¥¯¥é¥¹¡ä
  [SerializeField]
  private Text txtTime;

  [SeriallizeField]
  private Ease ease;

  private float duration = 1.0f; 


  public void UpdateDisplayTime(int oldTime, int newTime){
      txtTime.DOCounter(oldTime, newTime, duration).SetEase(ease);
  }



¡ãPresenter ¥¯¥é¥¹¡ä
¡¡using UniRx;

  [SerializeField]
  private Model model;

  [SerializeField]
  private View view;

  void Start() {
      model.Time
          .Zip(model.Time.Skip(1), (oldTime, newTime) => (oldTime, newTime))   // ¥¿¥×¥ë·¿¤òÍøÍѤ·¤Þ¤¹
          .Subscribe(x => view.UpdateDisplayTime(x.oldTime, x.newTime))
          .AddTo();
  }



¡¡°Ê¾å¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡
¡¡Â¾¤Ë¤â¼ÂÁõÊýË¡¤Ï¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢¿§¡¹¤Ê¤â¤Î¤òÄ´¤Ù¤Æ»î¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£



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


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

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

Menu


´ðÁÃ

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

private



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

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