ºÇ½ª¹¹¿·¡§ orika_ex_miyako 2022ǯ11·î20Æü(Æü) 19:40:53ÍúÎò
¼ê½ç£±£±¡¡¡¼MVP ¥Ñ¥¿¡¼¥ó¤Ë¤è¤ë¥ê¥¶¥ë¥Èɽ¼¨¤Î¼ÂÁõ¡¼
£±£·¡¥MVP ¥Ñ¥¿¡¼¥ó¤Î³Ø½¬¡
¡¡¿·¤·¤¤³Ø½¬ÆâÍƤϡ¢°Ê²¼¤ÎÄ̤ê¤Ç¤¹¡£
¡¡¡¦UniRx ¤Î ReactiveProperty ¤Î³èÍÑ ¡¡¡¦MVP ¥Ñ¥¿¡¼¥ó¤Ë¤è¤ë¥ê¥Õ¥¡¥¯¥¿¥ê¥ó¥°
¡¡Unity ¤Ë¤ª¤¤¤Æ UI ¤òɽ¼¨¤¹¤ëºÝ¤Ë¤Ï uGUI ¤Îµ¡Ç½¤ò³èÍѤ·¡¢Canvas Æâ¤Ë Text ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Ê¤É¤òÇÛÃÖ¤¹¤ë¤³¤È¤Ç¼ÂÁõ¤ò¹Ô¤¤¤Þ¤¹¡£
UI ¤Îɽ¼¨¤È¹¹¿·¤Ë¤Ä¤¤¤Æ¤Ï¡¢Web ´Ø·¸¤Ç³èÍѤµ¤ì¤Æ¤¤¤ë MVP (Model¡¢View¡¢Presenter)¥Ñ¥¿¡¼¥ó¤È¤¤¤¦Àß·×ÊýË¡¤òÍѤ¤¤¿À߷פò¹Ô¤¦¤³¤È¤¬½ÐÍè¤Þ¤¹¡£
¡¡¤³¤Á¤é¤Îµ¡Ç½¤ò¼ÂÁõ¤¹¤ë¤¿¤á¤Ë¤Ï¡¢UniRx ¤È¤¤¤¦¥¢¥»¥Ã¥È¤òÍøÍѤ·¤Þ¤¹¡£¤Þ¤º¤Ï¤½¤Á¤é¤ò¥¤¥ó¥Ý¡¼¥È¤·¤Æ¤«¤é³Ø½¬¤·¤Æ¤¤¤¤Þ¤¹¡£
¡¡
¡¡Ìµ½þ¤ÇÄ󶡤µ¤ì¤Æ¤¤¤ë¥é¥¤¥Ö¥é¥ê¤òÍøÍѤ·¤Þ¤¹¡£
¡¡Unity ¤Î¥¢¥»¥Ã¥È¥¹¥È¥¢¤Î¸¡º÷¤Ë¤Æ UniRx ¤ÈÆþÎϤ¹¤ë¤È¸¡º÷·ë²Ì¤È¤·¤Æɽ¼¨¤µ¤ì¤Þ¤¹¤Î¤Ç¡¢¤½¤Á¤é¤ò¥À¥¦¥ó¥í¡¼¥É¤·¤Æ Unity ¤Ë¥¤¥ó¥Ý¡¼¥È¤·¤Þ¤¹¡£
¤¢¤ë¤¤¤Ï²¼µ¤Î¥ê¥ó¥¯¤«¤éľÀÜ»²¾È¤â½ÐÍè¤Þ¤¹¡£
UniRx
https://assetstore.unity.com/packages/tools/integr...
¥¢¥»¥Ã¥È¥¹¥È¥¢
¡¡UniRx ¤È¤Ï¥ê¥¢¥¯¥Æ¥£¥Ö¥×¥í¥°¥é¥ß¥ó¥°¤È¤¤¤¦¹Í¤¨Êý¤ò Unity ¤ÇÍøÍѤǤ¤ë¤è¤¦¤ËÀ߷פµ¤ì¤Æ¤¤¤ë¥é¥¤¥Ö¥é¥ê¤Ç¤¹¡£
ÈóƱ´ü½èÍý¤È¥¤¥Ù¥ó¥È½èÍý¤ËÂФ·¤Æ¸úΨŪ¤Ê¼ÂÁõÊýË¡¤òÄ󶡤¹¤ë¹½Â¤¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£(Rx ¤Ï¥ê¥¢¥¯¥Æ¥£¥Ö¡¦¥¨¥¯¥¹¥Æ¥ó¥·¥ç¥ó¤Îά¹æ¤Ç¤¹¡£)
¡¡ÊØÍø¤«¤Ä¡¢¹âÅ٤ʽèÍý¤ò¼Â¸½¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¤¬¡¢³Ø½¬¥³¥¹¥È¤âÈó¾ï¤Ë¹â¤¤¤â¤Î¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
¤Þ¤¿³Ø½¬¤·¤¿¤«¤é¤È¤¤¤Ã¤Æ¡¢¤Ê¤ó¤Ç¤â¤³¤Î¹½Â¤¤Ë¤¹¤ì¤Ð¤¤¤¤¡¢¤È¤¤¤¦¤â¤Î¤Ç¤â¤¢¤ê¤Þ¤»¤ó¡£
¡¡º£²ó¤Ï¤½¤ÎÃæ¤Ç¤âÈæ³ÓŪ°·¤¤¤ä¤¹¤¯¡¢ÍøÍѤ¹¤ëµ¡²ñ¤Î¿¤¤µ¡Ç½¤Ë¤Ä¤¤¤Æ¡¢¿ô²ó¤Ëʬ¤±¤Æ¼ÂÁõ¤ò¹Ô¤¤¤Ê¤¬¤é³Ø½¬¤ò¹Ô¤Ã¤Æ¤¤¤¤Þ¤¹¡£
¡¡C# ¤Î´ðÁäÀ¤±¤Ç¤Ï¤Ê¤¯¡¢Linq¡¢¥é¥à¥À¼°(¤ª¤è¤Ó¡¢¥á¥½¥Ã¥É¥Á¥§¡¼¥ó)¤È¤¤¤Ã¤¿µ¡Ç½¤âÍý²ò¤·¤Æ¤¤¤Ê¤¤¤È°·¤¦¤³¤È¤¬Æñ¤·¤¤¤¿¤á¡¢
¤³¤ì¤é¤Îµ¡Ç½¤Ë¤Ä¤¤¤Æ¤Þ¤ÀÍý²ò¤¬ÉÔ½½Ê¬¤Ç¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢¤½¤Á¤é¤ò³Ø½¬¤·¤Æ¤«¤é¿Ê¤á¤ë¤è¤¦¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£
¡¡UniRx ¤Ë¤Ä¤¤¤Æ¤Ïµ»ö¤â¿¤¤¤Ç¤¹¤·¡¢»²¹Í¤È¤Ê¤ë½ñÀҤ⤢¤ê¤Þ¤¹¤Î¤Ç¡¢¤½¤Á¤é¤â¹ç¤ï¤»¤Æ³Ø½¬¤ò¹Ô¤¦¤è¤¦¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£
¡¡¥¹¥¯¥ê¥×¥ÈÆâ¤Ç UniRx ¤òÍøÍѤ¹¤ë¾ì¹ç¡¢using UniRx; ¤ÎÀë¸À¤¬É¬Íפˤʤê¤Þ¤¹¡£
¡¡UniRx ¤Ï¥Ç¥¶¥¤¥ó¥Ñ¥¿¡¼¥ó¤Î£±¤Ä¤Ç¤¢¤ë¡¢¥ª¥Ö¥¶¡¼¥Ð¡¼¥Ç¥¶¥¤¥ó¥Ñ¥¿¡¼¥ó¤È¤¤¤¦¤â¤Î¤ÇÀ߷פµ¤ì¤Æ¤¤¤Þ¤¹¡£
¡¡¶ñÂÎŪ¤Ë¤Ï¡¢¥¤¥Ù¥ó¥È(¥Ü¥¿¥ó¤Ê¤É)¤ò¼Â¹Ô¤·¤¿ºÝ¤Î½èÍý¤ò¡¢ÄÌÃΤ¹¤ë¦¡¢ÄÌÃΤò¼õ¤±¼è¤ë¦¡¢¤È¤¤¤¦³µÇ°¤òÍøÍѤ·¤Æ¼ÂÁõ¤ò¹Ô¤¦À߷פˤʤê¤Þ¤¹¡£
¡¡¤Ê¤ª¡¢²¼µ¤Î¥µ¥¤¥È¤ËÈó¾ï¤ËÃúÇ«¤Ê¹Í¤¨Êý¤¬½ñ¤¤¤Æ¤¢¤ê¤Þ¤¹¡£
¤³¤Á¤é¤òÆɤó¤Ç¤¤¤¿¤À¤¤¤¿¾å¤Ç¡¢º£¸å¤Î¼ê½ç¤ÏÀ߷פȼÂÁõ¤ò¹Ô¤¤¤Þ¤¹¡£
¡¡¤Þ¤ÀÆñ¤·¤¤ÆâÍƤǤ¢¤ë¤È´¶¤¸¤¿¾ì¹ç¤Ë¤Ï¡¢¤³¤ì°Ê¹ß¤Î¼ê½ç¤ÏÆñ¤·¤¤¤¿¤á¡¢¤è¤êÍý²ò¤ò¿¼¤á¤Æ¤«¤éºÆÅÙÄ©À魯¤ë¤è¤¦¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£
»²¹Í¥µ¥¤¥È
Qiita @toRisouP ÍÍ
¡ÚUnity¡ÛModel-View-(Reactive)Presenter¥Ñ¥¿¡¼¥ó¤È¤Ï²¿¤Ê¤Î¤«
https://qiita.com/toRisouP/items/5365936fc14c7e7ea...
¡¡°Ê²¼¤¬¡¢º£²ó¤Îµ¡Ç½¤ò¼ÂÁõ¤·¤Æ¤¤¤¯ºÝ¤ËºîÀ®¤¹¤ë¥¯¥é¥¹¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡¡¦Result_View ¡¡¡¦Result_Model ¡¡¡¦Presenter ¡¡¡¦MainGame
¡¡View ¥¯¥é¥¹¤È¤·¤Æ¥ê¥¶¥ë¥Èɽ¼¨¤ò¹Ô¤¦µ¡Ç½¤ò¤Þ¤È¤á¤Þ¤¹¡£
¡¡Model ¥¯¥é¥¹¤Ë¤Ï¥ê¥¶¥ë¥Èɽ¼¨¤ËÍøÍѤ¹¤ëÊÑ¿ô¤Î¾ðÊó¤ò UniRx ¤Î ReactiveProperty ¤òÍøÍѤ·¤Æ¤Þ¤È¤á¤Þ¤¹¡£
¡¡Presenter ¥¯¥é¥¹¤Ï¤³¤Î£²¤Ä¤Î¾ðÊó¤ò·ë¤ÓÉÕ¤±¤ë¤¿¤á¡¢Model ¥¯¥é¥¹¤Ë¤¢¤ë ReactiveProperty ¤Î¹ØÆɤò¹Ô¤¤¡¢View ¥¯¥é¥¹Â¦¤ËÄÌÃΤ·¤Þ¤¹¡£
¡¡MainGame ¥¯¥é¥¹¤Ï¡¢UI ɽ¼¨°Ê³°¤Î¡¢¥²¡¼¥à¤Î¼Â½èÍý¤ò¤Þ¤È¤á¤¿¥¯¥é¥¹¤Ç¤¹¡£
¤¤¤Þ¤Þ¤Ç¤¢¤ë GameManager ¥¯¥é¥¹¤ÈƱ¤¸Ìò³ä¤Ë¤Ê¤ê¤Þ¤¹(Ʊ¤¸Ì¾Á°¤Ç½¤Àµ¤¹¤ë¤Èʬ¤«¤ê¤Ë¤¯¤¯¤Ê¤ë¤¿¤á¡¢¿·¤·¤¤¥¯¥é¥¹¤È¤·¤ÆºîÀ®¤·¤Æ¤¤¤Þ¤¹)
¡¡¤Ä¤Å¤¤¤Æ Model ¥¯¥é¥¹¤òºîÀ®¤·¤Þ¤¹¡£
¤³¤Á¤é¤Ç¤Ï UniRx ¤Îµ¡Ç½¤Î£±¤Ä¤Ç¤¢¤ë ReactiveProperty ¤ò³èÍѤ·¡¢¥ª¥Ö¥¶¡¼¥Ð¡¼¥Ñ¥¿¡¼¥ó¤òÍøÍѤ·¤¿À߷פò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£
¡¡¥×¥ì¥¤¥ä¡¼¤Î¾¡Íø¿ô¤Î¥«¥¦¥ó¥È¤ò¹Ô¤¦¤¿¤á¤Î WinCount ÊÑ¿ô¤ò ReactiveProperty<int> ¤òºîÀ®¤·¡¢¤³¤Á¤é¤Î´Æ»ë(¹ØÆÉ)¤ò Presenter ¤Ç¹Ô¤¤¤Þ¤¹¡£
¤ª¤Ê¤¸¤¯¡¢·ë²Ìɽ¼¨ÍѤΠResultMessage ÊÑ¿ô¤â ReactiveProperty<string> ¤òºîÀ®¤·¡¢Æ±¤¸¤è¤¦¤Ë Presenter ¤Ë¤Æ¹ØÆɤ·¤Þ¤¹¡£
Result_Model.cs
¡¡GameManager ¥¹¥¯¥ê¥×¥È¤ò¸µ¤Ë¡¢MVP ¥Ñ¥¿¡¼¥ó¤Ç¤ÎÀ߷פËÂбþ¤·¤¿¥á¥¤¥ó½èÍý¤ò¹Ô¤¦¥¹¥¯¥ê¥×¥È¤òºîÀ®¤·¤Þ¤¹¡£
¤³¤Î¥¯¥é¥¹¤Ï¥²¡¼¥àÆâ¤Î¼Â½èÍý¤òµ½Ò¤·¤Þ¤¹¡£ºÇ½é¤Ë¤â½ñ¤¤¤¿¤è¤¦¤Ë¡¢¤¹¤Ù¤Æ¤Î½èÍý¤ò MVP ¥Ñ¥¿¡¼¥ó¤ËÅö¤Æ¤Ï¤á¤ëɬÍפϤ¢¤ê¤Þ¤»¤ó¡£
º£²ó¤Ç¤¢¤ì¤Ð¡¢¤¢¤¯¤Þ¤Ç¤â UI ɽ¼¨¤Ë´ØÏ¢¤¹¤ëµ¡Ç½¤Î¤ß¤òÀÚ¤êÎ¥¤·¤ÆÀ߷פ·¤Æ¤¤¤ë¤À¤±¤Ç¤¹¡£
¡¡¿·¤·¤¤¥¹¥¥ë¤Î½¬ÆÀ¤ò¤·¤¿¤È¤¡¢¤½¤ì¤À¤±¤ËÌÕÌÜŪ¤ËÍê¤ë¤³¤È¤Ï¤è¤¯¤¢¤ê¤Þ¤»¤ó¡£
»ëÌî¤ò¹¤¯¤â¤Ã¤Æ¡¢¼«Ê¬¤Î¥¹¥¥ë¤Î°ú¤½Ð¤·¤ò¹¤²¤ë¤Ä¤â¤ê¤Ç¼è¤êÁȤà¤È¤è¤¤¤Ç¤·¤ç¤¦¡£
¡¡ShowResult ¥á¥½¥Ã¥É¤¬¤Ê¤¯¤Ê¤Ã¤ÆÂå¤ï¤ê¤Î GameUp ¥á¥½¥Ã¥É¤¬Äɲ䵤줿¤ê¡¢ÊÑ¿ô¤ÎÀë¸À¤Ë ReactiveProperty ¤¬ÍøÍѤµ¤ì¤Æ¤¤¤Þ¤¹¡£
¤Þ¤¿¡¢¤¤¤Þ¤Þ¤Ç¤Ï Start ¥á¥½¥Ã¥É¤è¤ê InitialSettings ¥á¥½¥Ã¥É¤ò¼Â¹Ô¤·¤Æ¤¤¤Þ¤·¤¿¤¬¡¢¤³¤Á¤é¤â³°Éô¤Î¥¯¥é¥¹¤è¤ê¼Â¹Ô¤¹¤ëÀ߷פËÊѹ¹¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
MainGame.cs
¡¡View ¤Ë¤Ä¤¤¤Æ¤â¿·¤·¤¤¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òºîÀ®¤·¤Æ¥¢¥¿¥Ã¥Á¤·¤Æ¤â¤è¤¤¤Ç¤¹¤¬¡¢
¤¹¤Ç¤Ë Canvas Æâ¤Ë View ÍѤΥ²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤¬¤¢¤ë¤È»×¤¤¤Þ¤¹¤Î¤Ç¡¢¤½¤Á¤é¤Ë¥¢¥¿¥Ã¥Á¤·¤Æ¡¢Ì¾Á°¤â ¡Á View ¤ËÊѹ¹¤·¤Æ¤ª¤¤Þ¤¹¡£
¤Ç¤¤ì¤Ð¥Õ¥©¥ë¥ÀÌò¤Î¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òºî¤ê¡¢¤½¤ÎÃæ¤Ë Text ¤Ê¤É¤ò³ÊǼ¤·¤Æ´ÉÍý¤¹¤ë¤è¤¦¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£
¥Ò¥¨¥é¥ë¥¡¼²èÁü
Player_View ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È
Opponnet_View ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È
¡¡°Ê¾å¤ÇÀßÄê¤Ï´°Î»¤Ç¤¹¡£
¡¡³Æ¥¯¥é¥¹¤ÎÌò³ä¤ò¤ï¤«¤ê¤ä¤¹¤¯´ÉÍý¤¹¤ë¤¿¤á¡¢º£²ó¤Ï´û¸¤Î¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Ë¥¢¥¿¥Ã¥Á¤¹¤ë·Á¤Ç¤Ï¤Ê¤¯¡¢
³Æ Model ¤ä Presenter ¤´¤È¤Ë¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òºîÀ®¤·¤Æ¡¢¤½¤ì¤¾¤ì¤Î¥¯¥é¥¹¤ò¥¢¥¿¥Ã¥Á¤·¤Æ¤¤¤Þ¤¹¡£
¥Ò¥¨¥é¥ë¥¡¼²èÁü
MVP_Set(¥Õ¥©¥ë¥ÀÌò) ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È
Presenter ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È
MainGame ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È
Player_Model ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È
Opponent_Model ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È
¡¡°Ê¾å¤ÇÀßÄê¤Ï´°Î»¤Ç¤¹¡£
¡¡Àß·×¼«ÂΤ¬ÊѤï¤ê¡¢½èÍý¤Îµ½Ò¤Ï MVP ¥Ñ¥¿¡¼¥ó¤Ë¤Ê¤ê¤Þ¤·¤¿¤¬¡¢¤¢¤¯¤Þ¤Ç¤â¥ê¥Õ¥¡¥¯¥¿¥ê¥ó¥°¤Ë¤Ê¤ê¤Þ¤¹¤Î¤Ç¡¢¥²¡¼¥à¤ÎÆâÍƼ«ÂΤÏÊѤï¤ê¤Þ¤»¤ó¡£
¤è¤Ã¤Æ¡¢º£¤Þ¤Ç¤ÈƱ¤¸¤è¤¦¤Ë¥²¡¼¥à¤¬Í·¤Ù¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤«¤ò³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£
¡¡°Ê¾å¤Ç¤³¤Î¼ê½ç¤Ï½ªÎ»¤Ç¤¹¡£
¡¡¼¡¤Ï¡¡¼ê½ç£±£²¡¡¡ÝMVP ¥Ñ¥¿¡¼¥ó¤Ë¤è¤ë¥¤¥ó¥Õ¥©É½¼¨¤Î¼ÂÁõ¡Ý¡¡¤Ç¤¹¡£
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- ¥×¥í¥°¥é¥ß¥ó¥°
¥³¥á¥ó¥È¤ò¤«¤¯