ºÇ½ª¹¹¿·¡§ orika_ex_miyako 2023ǯ09·î15Æü(¶â) 11:26:04ÍúÎò
¼¡²ó¤Î¥²¡¼¥àµ¯Æ°»þ¤Ë¥í¡¼¥É¤ò¤·¤Æ¡¢¥²¡¼¥à¤ò¤ä¤á¤ëÁ°¤Ë½ê»ý¤·¤Æ¤¤¤¿¥¢¥¤¥Æ¥à¤Î¾ðÊó¤Î¾õÂÖ¤òÉü¸µ¤¹¤ëÀ©¸æ¤ò¼ÂÁõ¤·¤Þ¤¹¡£
¡ã¼ÂÁõ²èÁü¡¡¥»¡¼¥Ö¡ä
Æ°²è¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯
¡ã¼ÂÁõ²èÁü¡¡¥í¡¼¥É¡ä
Æ°²è¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯
¼ê½ç£²£²¡¡¡Ý½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¥»¡¼¥Ö¡¦¥í¡¼¥Éµ¡Ç½¤ÎÄɲáÝ
£³£¸¡¥GameData ¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¤Æ½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¾ðÊó¤Î¥»¡¼¥Öµ¡Ç½¤òÄɲä¹¤ë £³£¹¡¥GameData ¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¤Æ½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¾ðÊó¤Î¥í¡¼¥Éµ¡Ç½¤òÄɲä·¡¢°ÊÁ°¤ÈƱ¤¸½ê»ý½ç¤Çʤ٤ë
¡¡¿·¤·¤¤³Ø½¬ÆâÍƤϡ¢°Ê²¼¤ÎÄ̤ê¤Ç¤¹¡£
¡¡¡¦PlayerPrefs ¥¯¥é¥¹¡¡¡¼SetString¥á¥½¥Ã¥É¡¢Save ¥á¥½¥Ã¥É¡¢HasKey ¥á¥½¥Ã¥É¡¢GetString ¥á¥½¥Ã¥É¡¼ ¡¡¡¦String.Split ¥á¥½¥Ã¥É ¡¡¡¦¥³¥ó¥¹¥È¥é¥¯¥¿¡¡¡¼¥¤¥ó¥¹¥¿¥ó¥¹¤·¤¿¥¯¥é¥¹¤Ë¥³¥ó¥¹¥È¥é¥¯¥¿¤òÍøÍѤ·¤ÆÃͤòÂåÆþ¤¹¤ëÊýË¡¡¼ ¡¡¡¦Linq¤Îµ¡Ç½¤Î¼ÂÁõÎ㢡¡¡ÁOrderBy ¥á¥½¥Ã¥É¡Á ¡¡¡¦Enum.Parse ¥á¥½¥Ã¥É ¡¡¡¦int.Parse ¥á¥½¥Ã¥É
¡¡Èó¾ï¤Ë¿¤¯¤Îµ¡Ç½¤òÍøÍѤ·¤Æ¼ÂÁõ¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£
¡¡¥»¡¼¥Öµ¡Ç½¤è¤ê¤â¥í¡¼¥Éµ¡Ç½¤ÎÊý¤¬Ê£»¨¤Ç¤¹¤Î¤Ç¡¢¥»¡¼¥Öµ¡Ç½¤¬Æñ¤·¤¤¤È´¶¤¸¤¿¾ì¹ç¤Ë¤Ï¼ÂÁõ¤òÃæÃǤ·¤Æ¡¢½¼Ê¬¤ÊÃμ±¤Èµ»½Ñ¤òÍܤäƤ«¤éºÆÅÙÄ©À路¤Æ¤¯¤À¤µ¤¤¡£
¡¡½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¾ðÊó¤ò¥»¡¼¥Ö¤¹¤ëµ¡Ç½¤ò¼ÂÁõ¤·¤Þ¤¹¡£
¡¡¼ÂÁõ¤Ë¤¢¤¿¤Ã¤Æ¤Ï Unity ¤ÎÍÑ°Õ¤·¤Æ¤¤¤ë PlayerPrefs ¥¯¥é¥¹¤òÍøÍѤ·¤Þ¤¹¡£
¡¡½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¾ðÊó¤Ï GameData ¥¯¥é¥¹¤Ç´ÉÍý¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢
¥»¡¼¥Öµ¡Ç½¤â¤ª¤Ê¤¸ GameData ¥¯¥é¥¹Æâ¤ËÄɵ¤·¤Æ¼ÂÁõ¤¹¤ë¤è¤¦¤ÊÀ߷פˤ·¤Þ¤¹¡£
¡¡¤³¤ì¤Ï¥¢¥¤¥Æ¥à¤Î¾ðÊó¤ò´ÉÍý¤·¤Æ¤¤¤ë¥¯¥é¥¹¤Ç¤¢¤ë¤«¤é¤À¤±¤Ç¤Ï¤Ê¤¯¡¢
GameData ¥¯¥é¥¹¤¬¥·¥ó¥°¥ë¥È¥ó¥¯¥é¥¹¤Ç¤¢¤ë¤¿¤á¡¢¤³¤Î¥¯¥é¥¹Æâ¤Ë¥»¡¼¥ÖÍѤΥ᥽¥Ã¥É¤ò¼ÂÁõ¤·¤Æ¤ª¤¯¤³¤È¤Ë¤è¤ê¡¢
³°Éô¤Î¥¯¥é¥¹¤«¤éǤ°Õ¤Î¥¿¥¤¥ß¥ó¥°¤Ç¥»¡¼¥Ö¤Î½èÍý¤Î¸Æ¤Ó½Ð¤·Ì¿Îá¤ò¹Ô¤¤¤ä¤¹¤¯¤¹¤ë¤¿¤á¤Ç¤â¤¢¤ê¤Þ¤¹¡£
Î㤨¤Ð¡¢¥Õ¥£¡¼¥ë¥É¤ä¥À¥ó¥¸¥ç¥ó¤Ê¤É¡¢¤É¤³¤Ç¤â¥»¡¼¥Ö¤Ç¤¤ë¤è¤¦¤Ê¾õÂÖ¤òÁÛÄꤷ¤¿¾ì¹ç¤Ë¤Ï¡¢¼«Í³¤Ë¥»¡¼¥Ö¥á¥½¥Ã¥É¤¬¼Â¹Ô¤Ç¤¤ëÀ߷פÎÊý¤¬ÍøÊØÀ¤¬¹â¤¤¤È¸À¤¨¤Þ¤¹¡£
¡¡¥»¡¼¥Ö¤Î½èÍý¤ò¹Ô¤¦¥á¥½¥Ã¥É¤òºîÀ®¤·¡¢½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¾ðÊó¤ò¸µ¤Ë¥Ç¡¼¥¿¤Î¥»¡¼¥Ö¤ò¹Ô¤¤¤Þ¤¹¡£
¡¡¥Ç¥Ð¥Ã¥°ÍÑ¤Ë Update ¥á¥½¥Ã¥É¤òºîÀ®¤·¡¢¥¡¼¥Ü¡¼¥ÉÆþÎϤˤè¤Ã¤Æ¥»¡¼¥Ö¤¬¹Ô¤¨¤ë¤è¤¦¤Ë¤â½èÍý¤òÄɲä·¤Þ¤¹¡£
¤³¤Î½èÍý¤Ç¥Ç¥Ð¥Ã¥°¤ò¹Ô¤¤¡¢Ìµ»ö¤Ë¥»¡¼¥Ö¤¬¤Ç¤¤ë¤³¤È¤ò³Îǧ¤Ç¤¤ì¤Ð¡¢¤¢¤È¤Ï¡¢Ç¤°Õ¤Î¥¿¥¤¥ß¥ó¥°¤Ç¥»¡¼¥Ö¤Î½èÍý¤ò½ñ¤±¤Ð¤è¤¤¾õÂ֤ˤʤê¤Þ¤¹¡£
GameData.cs
¡¡¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¤¿¤é¥»¡¼¥Ö¤·¤Þ¤¹¡£
¡¡Unity ¤Ç¤Ï¥Ç¡¼¥¿¤Î¥»¡¼¥Ö¡¦¥í¡¼¥É¤ò¹Ô¤¦¤¿¤á¤Î PlayerPrefs ¥¯¥é¥¹¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
PlayerPrefs ¥¯¥é¥¹¤Ë¤Ï¥»¡¼¥Ö¡¦¥í¡¼¥ÉÍѤΥ᥽¥Ã¥É¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢¤³¤Á¤é¤ò¼ÂÁõ¤¹¤ë¤³¤È¤Ç
»ØÄꤷ¤¿¥Ç¡¼¥¿¤ò¥»¡¼¥Ö¤·¤¿¤ê¡¢¥í¡¼¥É¤·¤¿¤ê¤¹¤ë¤³¤È¤¬²Äǽ¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
¡¡¥Ç¡¼¥¿¤ÎÊݸÀè¤Ï¡¢Unity Editor ¤ä PC ¥²¡¼¥à¤Î¾ì¹ç¤Ë¤Ï PC ËÜÂΤΥϡ¼¥É¥Ç¥£¥¹¥¯¡¢Web ¤Î¾ì¹ç¤Ï¥Ö¥é¥¦¥¶Æâ¡¢¥¹¥Þ¥ÛüËö¤Î¾ì¹ç¤Ë¤Ï¥¢¥×¥êÆâ¤Î¥Ç¡¼¥¿¤Î¾ì½êÆâ¤Ç¤¹¡£
¡ãPlayerPrefs ¥¯¥é¥¹¡ä
https://docs.unity3d.com/ja/current/ScriptReferenc...
¡¡£²¤Ä¤Î¥á¥½¥Ã¥É¤òÍøÍѤ·¤Æ¥»¡¼¥Ö¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢½çÈÖ¤ËÀâÌÀ¤·¤Þ¤¹¡£
¡¡Key ¤È¤¤¤¦Ê¸»úÎó¤òÊݸ¤¹¤ëºÝ¤Î¼±Ê̻ҤȤ·¤Æ»ØÄꤷ¡¢¤½¤Î̾Á°¤òÍѤ¤¤Æ»ØÄꤵ¤ì¤¿·¿¤Î¾ðÊó¤ò¥»¡¼¥Ö¤¹¤ë¤¿¤á¤Î½àÈ÷¤ò¹Ô¤¤¤Þ¤¹¡£
Key ¤È¤Ï¤¤¤ï¤Ð¥»¡¼¥ÖÍѤΥé¥Ù¥ë¤Ç¤¢¤ê¡¢Ì¾Á°¤òÉÕ¤±¤ÆÊݸ¤Î¤³¤È¤Ç¤¹¡£¤³¤Î Key ¤Î¾ðÊó¤ò¥í¡¼¥É¤¹¤ëºÝ¤Ë¤âÍøÍѤ·¤Þ¤¹¡£
¡¡PlayerPrefs ¥¯¥é¥¹¤Ë¤Ï¥»¡¼¥Ö¤ÎÊýË¡¤¬£³¼ïÎàÍÑ°Õ¤µ¤ì¤Æ¤ª¤ê¡¢SetString ¥á¥½¥Ã¥É¤â¤½¤Î£±¤Ä¤Ç¤¹¡£
SetString ¤È¤¤¤¦Ì¾Á°¤ÎÄ̤ꡢʸ»úÎó¤ò¥»¡¼¥Ö¤·¤Æ¤ª¤¯¤³¤È¤¬½ÐÍè¤Þ¤¹¡£»Ä¤ë£²¤Ä¤Ï SetInt ¥á¥½¥Ã¥É¡¢SetFloat ¥á¥½¥Ã¥É¤Ç¤¢¤ê¡¢¤³¤ì¤é¤â¥á¥½¥Ã¥É̾¤Î·¿¤Î¾ðÊó¤ò¥»¡¼¥Ö¤·¤Þ¤¹¡£
¡¡º£²ó¥»¡¼¥Ö¤·¤¿¤¤¾ðÊó¤Ï¡¢¡Ú¥¢¥¤¥Æ¥à¤Î̾Á°¡Û¡Ú¥¢¥¤¥Æ¥à¤Î½ê»ý¿ô¡Û¡Ú¥¢¥¤¥Æ¥à¤ÎÄ̤·ÈÖ¹æ¡Û¤Î£³¤Ä¤Ç¤¹¤¬¡¢¤³¤ì¤é¤ÏÊ£¿ô¤Î·¿¤¬º®ºß¤·¤Æ¤¤¤Þ¤¹¡£
¤³¤¦¤¤¤Ã¤¿¥±¡¼¥¹¤Î¾ì¹ç¡¢¤½¤ì¤¾¤ì¤ò¸ÄÊ̤˥»¡¼¥Ö¤·¤Æ¤¤¤Æ¤ÏÈó¾ï¤Ë¸úΨ¤¬°¤¯¡¢¤Þ¤¿¥í¡¼¥É¤ò¹Ô¤¦ºÝ¤Ë¤âÉÔÊؤǤ¹¡£
¡¡¤½¤Î¤¿¤áº£²ó¤Ï¡¢¤³¤ì¤é£³¤Ä¤Î¾ðÊó¤ò£±¤Ä¤Îʸ»úÎó¤È¤·¤ÆºîÀ®¤·¡¢¤½¤Î¾õÂ֤ǥ»¡¼¥Ö¤ò¤·¤Þ¤¹¡£
¤Ä¤Þ¤ê¡¢¡Ú¥¢¥¤¥Æ¥à¤Î̾Á° + ¥¢¥¤¥Æ¥à¤Î½ê»ý¿ô + ¥¢¥¤¥Æ¥à¤ÎÄ̤·ÈÖ¹æ¡Û¤È¤¤¤¦¾õÂÖ¤Îʸ»úÎó¤òºîÀ®¤·¤Æ¡¢¤³¤ì¤ò£±²ó¤Ç¥»¡¼¥Ö¤ò¹Ô¤¦¤È¤¤¤¦¼êË¡¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡¤¿¤À¤·Ê¸»úÎó¤ò¤¯¤Ã¤Ä¤±¤ëºÝ¤Ë¤Ï¡¢¥í¡¼¥É¤¹¤ë»þ¤Î¤³¤È¤â¹Í¤¨¤ÆÃÖ¤«¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¤Î¤Ç¡¢¸·Ì©¤Ë¤Ï¡¢¥«¥ó¥Þ¤òÍøÍѤ·¤Æʸ»úÎó¤òºîÀ®¤·¤Þ¤¹¡£
¡¡°Ê¾å¤Î¤³¤È¤ò¤Õ¤Þ¤¨¤Æ¡¢¼¡¤Î¤è¤¦¤Ê½èÍý¤ò¼ÂÁõ¤·¤Æ¤¤¤Þ¤¹¡£
// ½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¿ô¤À¤±½èÍý¤ò¹Ô¤¦ for (int i = 0; i < itemInventryDatasList.Count; i++) { // ½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¾ðÊó¤ò£±¤Ä¤Îʸ»úÎó¤È¤·¤Æ¥»¡¼¥Ö¤¹¤ë¤¿¤á¤Î½àÈ÷¤ò¹Ô¤¦ PlayerPrefs.SetString(itemInventryDatasList[i].itemName.ToString(), itemInventryDatasList[i].itemName.ToString() + "," + itemInventryDatasList[i].count.ToString() + "," + i.ToString()); }
¡¡SetString ¥á¥½¥Ã¥É¤ÎÂè1°ú¿ô¤¬ Key ¤Ë¤Ê¤ê¤Þ¤¹¡£¡ÚitemInventryDatasList[i].itemName.ToString()¡Û¤ÎÉôʬ¤Ç¤¹¡£
º£²ó¤Ï¡¢¥¢¥¤¥Æ¥à¤Î̾Á°¤ò¤½¤Î¤Þ¤Þ Key ¤È¤·¤ÆÀßÄꤷ¤Æ¤¤¤Þ¤¹¡£
¤½¤Î¤¿¤á¡¢¥í¡¼¥É¤ò¹Ô¤¦ºÝ¤Ë¤â¥¢¥¤¥Æ¥à¤Î̾Á°¤ò¸¡º÷¤¹¤ë¤³¤È¤Ç³Îǧ¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤¤ëÀ߷פǤ¹¡£
¡¡SetString ¥á¥½¥Ã¥É¤ÎÂè2°ú¿ô¤¬¥»¡¼¥Ö¤µ¤ì¤ëʸ»úÎã¤Ë¤Ê¤ê¤Þ¤¹¡£
¡ÚitemInventryDatasList[i].itemName.ToString() + "," + itemInventryDatasList[i].count.ToString() + "," + i.ToString()¡Û¤ÎÉôʬ¤Ç¤¹¡£
Àè¤Û¤É¤âÀâÌÀ¤·¤¿¤è¤¦¤Ë¡¢£³¤Ä¤Î¾ðÊ󣳤ĤξðÊó¤¬Ê¬¤«¤ë¤è¤¦¤Ë¡¢¥«¥ó¥Þ¤Ç¶èÀڤ俾å¤Ç£±¤Ä¤Îʸ»úÎó¤È¤·¤Æ¥»¡¼¥Ö¤·¤Æ¤¤¤Þ¤¹¡£
¡Ú¥¢¥¤¥Æ¥à¤Î̾Á°, ¥¢¥¤¥Æ¥à¤Î½ê»ý¿ô , ¥¢¥¤¥Æ¥à¤ÎÄ̤·ÈÖ¹æ¡Û¤Î½çÈ֤Ǥ¹¡£
¡¡¤³¤ÎÊýË¡¤Ç¥»¡¼¥Ö¤·¤Æ¤ª¤¯¤³¤È¤Ç°Û¤Ê¤ë·¿¤Î¾ðÊó¤ò£±¤Ä¤Ë¥Ñ¥Ã¥±¡¼¥¸¤·¤Æ¥»¡¼¥Ö¤·¤Æ¤¤¤Þ¤¹¡£
¤³¤ì¤Ï¥¢¥¤¥Æ¥à¤Î¾ðÊ󣱤ĤˤĤ£±¤Ä¤º¤ÄºîÀ®¤µ¤ì¤Þ¤¹(for ʸ¤Ç¥ë¡¼¥×½èÍý¤·¤Æ¤¤¤Þ¤¹¡Ë¤Î¤Ç¡¢½ê»ý¥¢¥¤¥Æ¥à¤¬£³¤Ä¤¢¤ë¤Ê¤é¤Ð¡¢¤³¤Î£±¤Ä¤Ë¤Þ¤È¤Þ¤Ã¤¿Ê¸»úÎó¤â£³¤Ä¥»¡¼¥Ö¤µ¤ì¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡Set ¡Á ¤Ç»Ï¤Þ¤ë£³¤Ä¤Î¥á¥½¥Ã¥É¤Ï¡¢¥»¡¼¥Ö¤ò¹Ô¤¦ÂоݤòÀßÄꤷ¤Æ¤¤¤Þ¤¹¡£¤½¤Î¤¿¤á¥»¡¼¥Ö¤¹¤ë¤¿¤á¤Î½àÈ÷¤ò¹Ô¤¦¥á¥½¥Ã¥É¤Ç¤¹¡£
¼ÂºÝ¤Ë¤Ï¼¡¤Ë²òÀ⤹¤ë Save ¥á¥½¥Ã¥É¤ò¼Â¹Ô¤¹¤ë¤³¤È¤Ç¥Ç¡¼¥¿¤¬¥»¡¼¥Ö¤µ¤ì¤Þ¤¹¡£
»²¹Í¥µ¥¤¥È
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
PlayerPrefs.SetString
https://docs.unity3d.com/ja/current/ScriptReferenc...
¡¡Set ¡Á ¥á¥½¥Ã¥É¤Ë¤è¤Ã¤Æ½àÈ÷¤µ¤ì¤¿¾ðÊó¤ò¥»¡¼¥Ö¤¹¤ë¥á¥½¥Ã¥É¤Ç¤¹¡£
¤³¤Î½èÍý¤¬¼Â¹Ô¤µ¤ì¤Æ»Ï¤á¤Æ¥Ç¡¼¥¿¤¬¥»¡¼¥Ö¤µ¤ì¤Þ¤¹¡£
¡¡Ê£¿ô¤Î Set ¡Á ¥á¥½¥Ã¥É¤¬¼Â¹Ô¤µ¤ì¤Æ¤¤¤¿¾ì¹ç¡¢¤³¤Î¥á¥½¥Ã¥É¤Ï¤½¤ì¤é¤¹¤Ù¤Æ¤Î¥»¡¼¥Ö¤ò¹Ô¤¤¤Þ¤¹¡£
// ½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¿ô¤À¤±½èÍý¤ò¹Ô¤¦ for (int i = 0; i < itemInventryDatasList.Count; i++) { // ½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¾ðÊó¤ò£±¤Ä¤Îʸ»úÎó¤È¤·¤Æ¥»¡¼¥Ö¤¹¤ë¤¿¤á¤Î½àÈ÷¤ò¹Ô¤¦ PlayerPrefs.SetString(itemInventryDatasList[i].itemName.ToString(), itemInventryDatasList[i].itemName.ToString() + "," + itemInventryDatasList[i].count.ToString() + "," + i.ToString()); } // ¥»¡¼¥Ö PlayerPrefs.Save();
¡¡º£²ó¤Î¾ì¹ç¤Ë¤Ï¡¢for ʸÆâ¤Ç¥»¥Ã¥È¤µ¤ì¤¿Ê¸»úÎó¤Î¾ðÊó¤ò¤Þ¤È¤á¤Æ¥»¡¼¥Ö¤·¤Æ¤¤¤Þ¤¹¡£
»²¹Í¥µ¥¤¥È
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
PlayerPrefs.Save
https://docs.unity3d.com/ja/current/ScriptReferenc...
¡¡GameData ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤è¤ê¡¢¸½ºß½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¾ðÊó¤ò³Îǧ¤·¤Æ¤ª¤¤Þ¤¹¡£
¤Þ¤¿¡¢isDebug ¥Ü¥¿¥ó¤Ë¥Á¥§¥Ã¥¯¤òÆþ¤ì¤Æ¥Ç¥Ð¥Ã¥°Íѥ⡼¥É¤ËÀÚ¤êÂؤ¨¤Æ¤ª¤¤Þ¤¹¡£
¡ã¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü¡¡»²¹Í¡ä
¡¡¤³¤Î¥¢¥¤¥Æ¥à¤Î¾ðÊó¤ò¤½¤Î¤Þ¤Þ¤¹¤Ù¤Æ¥»¡¼¥Ö¤·¤Þ¤¹¡£¥¢¥¤¥Æ¥à¤Î̾Á°¡¢½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¿ô¡¢Ê¤ӽ礬¥»¡¼¥Ö¤µ¤ì¤Þ¤¹¡£
¡¡½àÈ÷¤¬À°¤Ã¤¿¤é¥²¡¼¥à¤ò¼Â¹Ô¤·¤Æ¡¢¡¡¥Ç¥Ð¥Ã¥°ÍѤ˥»¡¼¥ÖÍѤΥܥ¿¥ó¤òÀßÄꤷ¤Þ¤·¤¿¤Î¤Ç¡¢¤½¤Î¥Ü¥¿¥ó¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤¡£
Console ¥Ó¥å¡¼¤Ë¥»¡¼¥Ö¤·¤¿¥¡¼¤Î̾Á°¤È¡¢¤½¤Î¥¡¼¤Î̾Á°¤Ç¥»¡¼¥Ö¤µ¤ì¤¿¾ðÊ󤬤½¤ì¤¾¤ìɽ¼¨¤µ¤ì¤ì¤Ð¥»¡¼¥ÖÀ®¸ù¤Ç¤¹¡£
¡ã¼ÂÁõ²èÁü¡¡¥»¡¼¥Ö¡ä
Æ°²è¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯
¡¡°ìö¥»¡¼¥Ö¥Ç¡¼¥¿¤òÇË´þ¤¹¤ë¾ì¹ç¤Ë¤Ï¡¢Unity Editor ¤Îº¸¾å¤Ë¤¢¤ë¥á¥Ë¥å¡¼¤è¤ê¡¢Edit => Clear All PlayerPrefs ¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£
³Îǧ¤Î¥¦¥¤¥ó¥É¥¦¤¬³«¤¡¢Yes ¤òÁªÂò¤¹¤ë¤³¤È¤Ç¡¢PlayerPrefs ¤Ë¥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤ë¤¹¤Ù¤Æ¤Î¥Ç¡¼¥¿¤¬ºï½ü¤µ¤ì¤Þ¤¹¡£
¡ãClear All PlayerPrefs¡ä
¡¡°Ê¾å¤Ç¥»¡¼¥Ö¤Îµ¡Ç½¤Ï¼ÂÁõ´°Î»¤Ç¤¹¡£Â³¤¤¤Æ¡¢¤³¤Î¥»¡¼¥Ö¤·¤¿¥¢¥¤¥Æ¥à¤Î¾ðÊó¤ò¥í¡¼¥É¤¹¤ëµ¡Ç½¤ò¼ÂÁõ¤·¤Þ¤¹¡£
£³£¹¡¥GameData ¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¤Æ½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¾ðÊó¤Î¥í¡¼¥Éµ¡Ç½¤òÄɲä·¡¢°ÊÁ°¤ÈƱ¤¸½ê»ý½ç¤Çʤ٤ë
¡¡½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¾ðÊ󤬥»¡¼¥Ö¤Ç¤¤Þ¤·¤¿¤Î¤Ç¡¢¼¡¤Ï¤³¤Î¥Ç¡¼¥¿¤ò¥í¡¼¥É¤¹¤ë½èÍý¤ò¼ÂÁõ¤·¤Þ¤¹¡£
¥í¡¼¥É½èÍý¤Ë¤Ä¤¤¤Æ¤â PlayerPrefs ¥¯¥é¥¹¤Îµ¡Ç½¤òÍøÍѤ·¤Æ¼ÂÁõ¤ò¹Ô¤¤¤Þ¤¹¡£
¡¡¥í¡¼¥É½èÍý¤â¡¢Î㤨¤Ð¡¢¥¿¥¤¥È¥ë²èÌ̤«¤é¸Æ¤Ó½Ð¤¹¤è¤¦¤Ë¤Ê¤ë¤Î¤«¡¢¥²¡¼¥àÆâ¤Ç¸Æ¤Ó½Ð¤¹¤è¤¦¤Ë¤Ê¤ë¤Î¤«¡¢
ÍøÍѤ¹¤ë¾ì½ê¤¬Â¿´ô¤ËÅϤë¤ÈÁÛÄꤵ¤ì¤Þ¤¹¤Î¤Ç¡¢¤ä¤Ï¤ê¡¢¤³¤Î½èÍý¤â GameData ¥¯¥é¥¹¤Ë¼ÂÁõ¤ò¹Ô¤¦À߷פˤ·¤Þ¤¹¡£
¡¡¼ÂÁõ¤¹¤ë¥á¥½¥Ã¥É¤Ï£±¤Ä¤À¤±¤Ç¤¹¤¬¡¢½èÍý¤¬Ê£»¨¤Ç¤¹¡£
ÍøÍѤ·¤Æ¤¤¤ë¥á¥½¥Ã¥É¤Ë¤Ä¤¤¤Æ¤Ï¸å¤Ç²òÀ⤷¤Æ¤¤¤Þ¤¹¤·¡¢½èÍý¤Îή¤ì¤â¥³¥á¥ó¥È¤·¤Æ¤¢¤ê¤Þ¤¹¤¬
¤½¤ì¤Ç¤â°ìÆɤ·¤¿¤À¤±¤Ç¤ÏÍý²ò¤¬Æñ¤·¤¤¤È»×¤¤¤Þ¤¹¤Î¤Ç¡¢·«¤êÊÖ¤·Æɤ߲ò¤¤¤Æ¤¤¤Ã¤Æ¤¯¤À¤µ¤¤¡£
¡¡¤Þ¤¿ Update ¥á¥½¥Ã¥É¤Ë¥í¡¼¥ÉÍѤνèÍý¤ò¼ÂÁõ¤·¤Æ¤ª¤¤Þ¤¹¡£
º£²ó¤âǤ°Õ¤Î¥¿¥¤¥ß¥ó¥°¤Ç¥Ü¥¿¥ó¤ò²¡¤·¤Æ¥í¡¼¥É¤ò¹Ô¤Ã¤Æ¤ß¤ÆÌäÂ꤬¤Ê¤±¤ì¤Ð¤É¤Î¥¹¥¯¥ê¥×¥È¤Ëµ½Ò¤·¤Æ¤âÂç¾æÉפǤ·¤ç¤¦¡£
GameData.cs
¡¡¥¹¥¯¥ê¥×¥È¤ò½¤Àµ¤·¤¿¤é¥»¡¼¥Ö¤·¤Þ¤¹¡£
¡¡PlayerPrefs ¥¯¥é¥¹¤Î°·¤¨¤ë¥á¥½¥Ã¥É¤ò¿·¤·¤¯£²¤ÄÍøÍѤ·¤Æ¤¤¤Þ¤¹¡£
¡¡°ú¿ô¤Ë»ØÄꤷ¤¿Ê¸»úÎó¤¬ PlayerPrefs ¤ËÊݸ¤µ¤ì¤Æ¤¤¤ë Key ¤Î¾ðÊó¤È¤·¤Æ¤¢¤ë¤«¤òÄ´¤Ù¤Æ¡¢Key ¤¬Â¸ºß¤·¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï true¡¢Â¸ºß¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï false ¤òÌᤷ¤Þ¤¹¡£
// ItemName ¤Ç¥»¡¼¥Ö¤·¤Æ¤¢¤ë¥Ç¡¼¥¿¤¬ PlayerPrefs Æâ¤Ë¤¢¤ë¤« if (!PlayerPrefs.HasKey(DataBaseManager.instance.GetItemDataFromItemNo(i).itemName.ToString())) { ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡ // ¥»¡¼¥Ö¥Ç¡¼¥¿¤¬¤Ê¤±¤ì¤Ð¤³¤³¤Ç½èÍý¤ò½ªÎ»¤·¡¢¼¡¤Î¥»¡¼¥Ö¥Ç¡¼¥¿¤ò³Îǧ¤¹¤ë½èÍý¤Ø°Ü¤ë continue; }
¡¡º£²ó¤Î¥±¡¼¥¹¤Ç¤Ï¡¢Key ¤Î³Îǧ¤ò¹Ô¤¤¡¢¤½¤Î¸ºß¤¬¤Ê¤¤¾ì¹ç(false)¤Ë¤Ï¼¡¤Î½èÍý¤Ë¤Ï¤¤¤«¤º¡¢continue ½èÍý¤Ë¤è¤Ã¤Æ¡¢¼¡¤Î for ʸ¤Î½èÍý¤Ë°Ü¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
Key ¤¬Â¸ºß¤·¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¤³¤Î if ʸ¤Ë¤ÏÆþ¤é¤Ê¤¯¤Ê¤ë¤¿¤á¡¢if ʸ¤Î²¼¤Ë¤¢¤ë½èÍý¤¬¼Â¹Ô¤µ¤ì¤Þ¤¹¡£
»²¹Í¥µ¥¤¥È
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
PlayerPrefs.HasKey
https://docs.unity3d.com/ja/current/ScriptReferenc...
¡¡PlayerPrefs Æâ¤Ë¥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤ë Key ¤¬Â¸ºß¤·¤Æ¤¤¤ë¾ì¹ç¡¢¤½¤Î¾ðÊó¤ò string ·¿¤Ç¼èÆÀ¤¹¤ë¥á¥½¥Ã¥É¤Ç¤¹¡£
Âè2°ú¿ô¤òÀßÄꤹ¤ë¤³¤È¤Ç¡¢¤â¤·¤â Key ¤¬Â¸ºß¤·¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï Default ÃͤȤ·¤ÆÀßÄê¤ò¹Ô¤¦¤³¤È¤â½ÐÍè¤Þ¤¹¡£
¡¡
// ¥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤ë¥Ç¡¼¥¿¤òÆɤ߹þ¤ó¤ÇÇÛÎó¤ËÂåÆþ string[] stringArray = PlayerPrefs.GetString(DataBaseManager.instance.GetItemDataFromItemNo(i).itemName.ToString()).Split(',');
¡¡º£²ó¤Î¥±¡¼¥¹¤Ç¤Ï¡¢DataBaseManager.instance.GetItemDataFromItemNo(i).itemName.ToString() ¥á¥½¥Ã¥É¤ÎÌá¤êÃͤò Key ¤È¤·¤Æ»ØÄꤷ¤Æ¤¤¤Þ¤¹¡£
"ÌôÁð" ¤ä "¤¯¤µ¤ê¤«¤¿¤Ó¤é" ¤È¤¤¤Ã¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤ÇÊݸ¤µ¤ì¤Æ¤¤¤ë¥Ç¡¼¥¿¤¬ PlayerPrefs ¤Ë¸ºß¤·¤Æ¤¤¤ë¤«¤ò³Îǧ¤·¡¢Â¸ºß¤·¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¢
ʸ»úÎó¤È¤·¤Æ¾ðÊó¤ò¼èÆÀ¤·¤Þ¤¹¡£¤½¤Î¸å¡¢¼èÆÀ¤·¤¿Ê¸»úÎó¤ËÂФ·¤Æ¡¢Split ¥á¥½¥Ã¥É¤¬¼Â¹Ô¤µ¤ì¤Þ¤¹¡£
»²¹Í¥µ¥¤¥È
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
PlayerPrefs.GetString
https://docs.unity3d.com/ja/current/ScriptReferenc...
¡¡Split ¥á¥½¥Ã¥É¤Ï String ¥¯¥é¥¹¤¬»ý¤Äµ¡Ç½¤Î£±¤Ä¤Ç¤¹¡£ÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢using System ¤ÎÀë¸À¤¬É¬Íפˤʤê¤Þ¤¹¡£
¡¡£±¤Ä¡¢¤Þ¤¿¤ÏÊ£¿ô¤Î¶èÀÚµ¹æ¤ò»ý¤Ä1¤Ä¤Îʸ»úÎó¤òÊ£¿ô¤Îʸ»úÎó¤Ëʬ³ä¤·¤ÆÇÛÎó¤òºîÀ®¤¹¤ëµ¡Ç½¤Ç¤¹¡£
// ItemName ¤Ç¥»¡¼¥Ö¤·¤Æ¤¢¤ë¥Ç¡¼¥¿¤¬¤¢¤ë¤« string[] stringArray = PlayerPrefs.GetString(DataBaseManager.instance.GetItemDataFromItemNo(i).itemName.ToString()).Split(',');
¡¡º£²ó¤Î¥±¡¼¥¹¤Ç¤Ï¡¢string ·¿¤Î£±¤Ä¤Îʸ»úÎó¤È¤·¤Æ¥¢¥¤¥Æ¥à¤Î¾ðÊ󤬥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤ë¤«¤ò³Îǧ¤·¡¢¥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤¿¾ì¹ç¤Ë¤Ï¡¢£±¤Ä¤Îʸ»úÎó¤Î¾ðÊ󤬼èÆÀ½ÐÍè¤Þ¤¹¡£
¤½¤ì¤Ï¡Ú¥¢¥¤¥Æ¥à¤Î̾Á°, ¥¢¥¤¥Æ¥à¤Î½ê»ý¿ô, ½ê»ý¤·¤Æ¤¤¤ëºÝ¤ÎÄ̤·ÈÖ¹æ¡Û¤È¤¤¤¦½çÈ֤ǥ«¥ó¥Þ¶èÀڤꤵ¤ì¤Æ¤¤¤ëʸ»úÎó¤Î¾ðÊó¤Ë¤Ê¤ê¤Þ¤¹¡£
Î㤨¤Ï¡¢[ÌôÁð,1,0] [¤¯¤µ¤ê¤«¤¿¤Ó¤é,2,1] ¤È¤¤¤¦¤è¤¦¤Ê¾ðÊó¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
¡¡¥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¥Ç¡¼¥¿¤Ï¤¹¤Ù¤Æ¤³¤Î½ñ¼°¤Ë¤è¤Ã¤Æ¥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢¤â¤·¤â¥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤ë¥Ç¡¼¥¿¤ò¼èÆÀ¤Ç¤¤Æ¤â
¤½¤Î¤Þ¤Þ¤Î¾õÂ֤Ǥϥ²¡¼¥àÆâ¤ÇÍøÍѤǤ¤ë¾õÂ֤ˤʤäƤ¤¤Þ¤»¤ó¡£
¡¡¤½¤³¤Ç¤Þ¤º¤Ï¡¢¤³¤Î£±¤Ä¤Îʸ»úÎó¤ò¡Ö¥«¥ó¥Þ¡×¤ÎÉôʬ¤Ç¶èÀڤäƤ¤¤¡¢¤½¤ì¤òÇÛÎó¤Ë¤¹¤ë½èÍý¤ò¹Ô¤¤¤Þ¤¹¡£
¤½¤ì¤ò¹Ô¤¦¥á¥½¥Ã¥É¤¬ Split ¥á¥½¥Ã¥É¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡Split ¥á¥½¥Ã¥É¤Ïʸ»úÎó(string ·¿)¤ËÂФ·¤Æ¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¥á¥½¥Ã¥É¤Ç¤¹¡£°ú¿ô¤Ç»ØÄꤷ¤¿Ê¸»ú(char ·¿)¤ÎÉôʬ¤ÇÂоݤȤʤëʸ»úÎó¤ò¶èÀڤꡢ¤½¤ì¤òÇÛÎó¤Ë¤·¤Þ¤¹¡£
¡¡Àè¤Û¤É¤ÎÎã¤Î [ÌôÁð,1,0] ¤È¤¤¤¦Ê¸»úÎó¤Ç¤¢¤ì¤Ð [ÌôÁð] [1] [0] ¤È¤¤¤¦¤è¤¦¤Ë¡¢¥«¥ó¥Þ¤ÎÉôʬ¤Ç¶èÀڤä¿Ê¸»úÎó¤òºîÀ®¤·¤Þ¤¹¡£
¤³¤ì¤òÀèƬ¤«¤éÇÛÎó¤Ë¤·¤Þ¤¹¡£
¡¡¾åµ¤ÎÎã¤ò¸µ¤ËºîÀ®¤µ¤ì¤ë string[] stringArray ÊÑ¿ô¤Ï¡¢¼¡¤Î¤è¤¦¤Ê¾õÂ֤ˤʤäƤ¤¤Þ¤¹¡£
¡ã[ÌôÁð] [1] [0] ¤ò¥«¥ó¥Þ¤Ç¶èÀڤ俺ݤΠstring[] stringArray ÊÑ¿ô¤ÎÍ×ÁÇ¡ä
stringArray[0] = "ÌôÁð" stringArray[1] = "1" stringArray[2] = "0"
¡¡¿ô»ú¤Î¾ðÊó¤âʸ»úÎó¤Ç¤¢¤ë¤³¤È¤ËÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£¤Þ¤¿¡¢¶èÀÚʸ»ú¤È¤·¤Æ»ØÄꤵ¤ì¤Æ¤¤¤ëʸ»ú¤Ï¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤Þ¤¹¡£
º£²ó¤Ï¥«¥ó¥Þ¤ò¶èÀÚʸ»ú¤È¤·¤Æ»ØÄꤷ¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢¤½¤Î¾ðÊó¤Ïºï½ü¤µ¤ì¤Æ¡¢¥«¥ó¥Þ¤ò½ü¤¤¤¿Ê¸»úÎó¤ÎÇÛÎ󤬺îÀ®¤µ¤ì¤Þ¤¹¡£
¡¡£±¤Ä£±¤Ä¤Î½èÍý¤ò¤·¤Ã¤«¤ê¤ÈÆɤ߲ò¤¤¤Æ¤¤¤¯¤³¤È¤ò³Ð¤¨¤Æ¤¤¤¤Þ¤·¤ç¤¦¡£
»²¹Í¥µ¥¤¥È
MicroSoft C# ¥É¥¥å¥á¥ó¥È
C# ¤Ç String.Split ¤ò»ÈÍѤ·¤Æʸ»úÎó¤òʬ³ä¤¹¤ëÊýË¡
https://docs.microsoft.com/ja-jp/dotnet/csharp/how...
SAMURAI ¥¨¥ó¥¸¥Ë¥¢¥Ö¥í¥° ÍÍ
¡ÚC#ÆþÌç¡ÛString.Split¤Çʸ»úÎó¤òʬ³ä(Ê£¿ôʸ»ú¡¢Ê¸»ú¿ô¤Ç¤âʬ³ä)
https://www.sejuku.net/blog/44242
¡¡¥³¥ó¥¹¥È¥é¥¯¥¿¤È¤Ï¡¢¥¯¥é¥¹¤¬¥¤¥ó¥¹¥¿¥ó¥¹¡Ênew ¤Ë¤è¤Ã¤Æ½é´ü²½¡Ë¤µ¤ì¤¿¤È¤¤Ë¡¢°ú¿ô¤Ç»ØÄꤷ¤¿ÃͤÎÂåÆþ¤ò¶¯À©¤¹¤ëÆüì¤Ê¥á¥½¥Ã¥É¤Î¤³¤È¤Ç¤¹¡£
¥¯¥é¥¹Ì¾¡Ê·¿Ì¾¡Ë¤ÈƱ¤¸Ì¾Á°¤ÇÄêµÁ¤òºîÀ®¤·¤Þ¤¹¡£¥³¥ó¥¹¥È¥é¥¯¥¿¤Ï¥á¥½¥Ã¥É¤Ç¤¹¤¬Ìá¤êÃͤò»ý¤Á¤Þ¤»¤ó¡£¡ÊÀµ³Î¤Ë¤¤¤¦¤ÈÌá¤êÃͤòÊÖ¤»¤Þ¤»¤ó¡£¡Ë
¡¡¥á¥½¥Ã¥É¤Ç¤¹¤Î¤Ç¡¢¥¯¥é¥¹Æâ¤ËÄêµÁ¤òºîÀ®¤·¤Þ¤¹¡£
[System.Serializable] public class ItemInventryData { public ItemName itemName; // ¥¢¥¤¥Æ¥à¤Î̾Á° public int count; // ½ê»ý¿ô public int number; // ½ê»ý¤·¤Æ¤¤¤ëÄ̤·ÈÖ¹æ /// <summary> /// ItemInventryData ¥¯¥é¥¹¤Î¥³¥ó¥¹¥È¥é¥¯¥¿ /// </summary> /// <param name="name">¥¢¥¤¥Æ¥à¤Î̾Á°</param> /// <param name="value">¥¢¥¤¥Æ¥à¤Î½ê»ý¿ô</param> /// <param name="num">¥¢¥¤¥Æ¥à¤ò½ê»ý¤·¤¿ºÝ¤ÎÄ̤·ÈÖ¹æ</param> public ItemInventryData(ItemName name, int value, int num) {¡¡¡¡¡¡//¡¡Ìá¤êÃͤ¬¤¢¤ê¤Þ¤»¤ó itemName = name; count = value; number = num; } }
¡¡¥¯¥é¥¹¤ÇÍÑ°Õ¤·¤Æ¤¤¤ëÊÑ¿ô¤ËÂФ·¤Æ¡¢¥¤¥ó¥¹¥¿¥ó¥¹¤òÀµ¤·¤¯(ÂåÆþ˺¤ì¤Î¤Ê¤¤¤è¤¦¤Ë)½èÍý¤ò¹Ô¤¦¤¿¤á¤ËÍÑ°Õ¤µ¤ì¤Þ¤¹¡£
¡¡¥³¥ó¥¹¥È¥é¥¯¥¿¤ò»ÈÍѤ¹¤ë¾ì¹ç¤Ë¤Ï¡¢new ¤Ë¤è¤ë½é´ü²½¤ÎÀë¸À¤ÈƱ»þ¤Ë¡¢¥³¥ó¥¹¥È¥é¥¯¥¿¤Ç°ú¿ô¤òÄêµÁ¤·¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¢°ú¿ô¤¬É¬Íפˤʤê¤Þ¤¹¡£
°ú¿ô¤¬É¬Íפʾì¹ç¤Ë°ú¿ô¤¬¤Ê¤¤¾ì¹ç¤Ë¤Ï¥¨¥é¡¼¤Ë¤Ê¤ê¤Þ¤¹¡£¤³¤ì¤¬ÃͤÎÂåÆþ¤ò¶¯À©¤¹¤ë¡¢¤È¤¤¤¦°ÕÌ£¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡½é´ü²½¤ÎÊýË¡¤Ç¤¹¡£²¼µ¤Î½èÍýÆâ¤Î¡¢Add ¥á¥½¥Ã¥ÉÆâ¤Ç¼Â¹Ô¤µ¤ì¤Æ¤¤¤ë½èÍý¤¬¥¯¥é¥¹¤ò¥¤¥ó¥¹¥¿¥ó¥¹¤·¡¢½é´ü²½¤·¤Æ¤¤¤ëÉôʬ¤Ç¤¹¡£
// ¥»¡¼¥Ö¥Ç¡¼¥¿¤«¤é¥¢¥¤¥Æ¥à¤Î¥Ç¡¼¥¿¤ò¥³¥ó¥¹¥È¥é¥¯¥¿¡¦¥á¥½¥Ã¥É¤òÍøÍѤ·¤ÆÉü¸µ itemInventryDatasList.Add(new ItemInventryData((ItemName)Enum.Parse(typeof(ItemName), stringArray[0]), int.Parse(stringArray[1]), int.Parse(stringArray[2])));
¡ã¾åµ¤Î½èÍý¤Î¤¦¤Á¡¢¤³¤ÎÉôʬ¤¬¥¯¥é¥¹¤ò¥¤¥ó¥¹¥¿¥ó¥¹¤·¤Æ¤¤¤ëÉôʬ¡ä
new ItemInventryData((ItemName)Enum.Parse(typeof(ItemName), stringArray[0]), int.Parse(stringArray[1]), int.Parse(stringArray[2]))
¡¡¥³¥ó¥¹¥È¥é¥¯¥¿¤ò»ý¤Ä¥¯¥é¥¹¤¬¥¤¥ó¥¹¥¿¥ó¥¹¤µ¤ì¤ë¤È¡¢¥³¥ó¥¹¥È¥é¥¯¥¿¡¦¥á¥½¥Ã¥É¤¬¼«Æ°Åª¤Ë¸Æ¤Ó½Ð¤µ¤ì¤Æ¡¢½é´ü²½¤Î½èÍý¤¬¹Ô¤ï¤ì¤Þ¤¹¡£
½èÍý¤ÎÆâÍƤÏÄ̾ï¤Î¥á¥½¥Ã¥É¤ÈƱ¤¸¤Ç¤¹¡£Â¿¤¯¤Î¾ì¹ç¤Ï¤³¤³¤Ç¡¢¥¯¥é¥¹¤ËÍÑ°Õ¤·¤Æ¤¤¤ëÊÑ¿ô¤ËÂФ·¤Æ¡¢°ú¿ô¤ÎÃͤòÂåÆþ¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¥¯¥é¥¹¤Ë½é´ü¾ðÊó¤òÅÐÏ¿¤·¤Þ¤¹¡£
¡ãnew ItemInvenrtyData ¤¬¼Â¹Ô¤µ¤ì¤ë¤È¡¢¥³¥ó¥¹¥È¥é¥¯¥¿¤¬½èÍý¤µ¤ì¤ë¡¡=¡¡½é´ü²½¡ä
public ItemInventryData(ItemName name, int value, int num) { // <= ¤³¤³¤Ë°ú¿ô¤Î¾ðÊó¤¬ÆϤ¯ itemName = name;¡¡¡¡//¡¡name ÊÑ¿ô¤Ë¤Ï¡¢Âè1°ú¿ô¤ÎÃͤǤ¢¤ë (ItemName)Enum.Parse(typeof(ItemName), stringArray[0]) ¤ÎÌá¤êÃͤ¬ÂåÆþ¤µ¤ì¤Æ¤¤¤ë count = value; // value ÊÑ¿ô¤Ë¤Ï¡¢Âè2°ú¿ô¤ÎÃͤǤ¢¤ë int.Parse(stringArray[1]) ¤ÎÌá¤êÃͤ¬ÂåÆþ¤µ¤ì¤Æ¤¤¤ë number = num; // num ÊÑ¿ô¤Ë¤Ï¡¢Âè3°ú¿ô¤ÎÃͤǤ¢¤ë int.Parse(stringArray[2]) ¤ÎÌá¤êÃͤ¬ÂåÆþ¤µ¤ì¤Æ¤¤¤ë }
¡¡¥³¥ó¥¹¥È¥é¥¯¥¿¤Ï¥ª¡¼¥Ð¡¼¥í¡¼¥É¤¬²Äǽ¤Ç¤¹¡£¤½¤Î¤¿¤á¡¢Æ±¤¸Ì¾Á°¤Î¥³¥ó¥¹¥È¥é¥¯¥¿¡¦¥á¥½¥Ã¥É¤Ç¤¢¤Ã¤Æ¤â°ú¿ô¤òÊÌ¡¹¤Î·Á¤ÇÄêµÁ¤·¤Æ¤ª¤¯¤³¤È¤¬²Äǽ¤Ç¤¹¡£
Î㤨¤Ð¡¢°Ê²¼¤Î¤è¤¦¤Ê·Á¤ÇÍÑ°Õ²Äǽ¤Ç¤¹¡£¥ª¡¼¥Ð¡¼¥í¡¼¥É¤¬¤¢¤ë¾ì¹ç¡¢¥¯¥é¥¹¤ò¥¤¥ó¥¹¥¿¥ó¥¹¤·¤¿¤È¤¡¢°ú¿ô¤Î¾ðÊó¤Ë¹ç¤ï¤»¤ÆŬÍѤ¹¤ë¥³¥ó¥¹¥È¥é¥¯¥¿¤¬¼«Æ°Åª¤ËÊѤï¤ê¤Þ¤¹¡£
¡ã¥³¥ó¥¹¥È¥é¥¯¥¿¡¦¥á¥½¥Ã¥É¤Î¥ª¡¼¥Ð¡¼¥í¡¼¥É¡ä
// ¤½¤Î£± public ItemInventryData(ItemName name, int value, int num) { itemName = name; count = value; number = num; } // ¤½¤Î£² public ItemInventryData(ItemName name, int value, int num, ItemType type) { itemName = name; count = value; number = num; itemType = type; } // ¤½¤Î£³ public ItemInventryData(ItemName name) { itemName = name; }
»²¹Í¥µ¥¤¥È
̤³ÎǧÈô¹ÔCÍÍ
¥³¥ó¥¹¥È¥é¥¯¥¿
https://ufcpp.net/study/csharp/oo_construct.html
¡¡»ØÄꤷ¤¿¥³¥ì¥¯¥·¥ç¥óÆâ¤ÎÍ×ÁǤò¡¢°ú¿ô¤Ç»ØÄꤷ¤¿¾ðÊó¤ò´ð½à¤Ë¾º½ç¤ËʤÓÂؤ¨¤ëµ¡Ç½¤Ç¤¹¡£½èÍý¤Î·ë²Ì¤ÏÌá¤êÃͤȤ·¤Æ¼èÆÀ½ÐÍè¤Þ¤¹¡£
// °ÊÁ°¤Ë½ê»ý¤·¤Æ¤¤¤¿ÈÖ¹æ½ç¤Ç½ê»ý¥¢¥¤¥Æ¥à¤Îʤӽç¤ò¥½¡¼¥È itemInventryDatasList = itemInventryDatasList.OrderBy(x => x.number).ToList();
¡¡º£²ó¤Î¥±¡¼¥¹¤Ç¤Ï¡¢itemInventryDatasList ÊÑ¿ô¤òÂоݤȤ·¤Æ OrderBy ¥á¥½¥Ã¥É¤ò¼Â¹Ô¤·¤Æ¤¤¤Þ¤¹¡£
itemInventryDatasList ÊÑ¿ô¤Ï ItemInventryData ¥¯¥é¥¹¤Î½¸¹çÂΤǤ¹¤Î¤Ç¡¢¤³¤ì¤ò°ú¿ô¤Ç»ØÄꤷ¤¿ ItemInventryData ¥¯¥é¥¹¤Î number ÊÑ¿ô¤ò³Îǧ¤·¤Æ¾º½ç¤ËʤÓÂؤ¨¤Þ¤¹¡£
number ÊÑ¿ô¤Ï¡¢¥²¡¼¥àÆâ¤Ç¥¢¥¤¥Æ¥à¤ò¼èÆÀ¤·¤¿ºÝ¤ÎÄ̤·ÈÖ¹æ¤Ç¤¹¡£¿ô»ú¤¬Ä㤤¤Û¤ÉÀè¤ËÆþ¼ê¤·¡¢¿ô»ú¤¬¹â¤¤¤Û¤É¸å¤ÇÆþ¼ê¤·¤¿¥¢¥¤¥Æ¥à¤È¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
¡¡ºÇ¸å¤Ë ToList ¥á¥½¥Ã¥É¤ò¼Â¹Ô¤·¤Æ¥¥ã¥¹¥È¤¹¤ë¤³¤È¤Ë¤è¤ê¡¢ºÆ¤Ó List ¤È¤·¤Æ¹½ÃÛ¤µ¤ì¤Þ¤¹¡£
¡¡¤³¤Î·ë²Ì¡¢¥í¡¼¥É¤µ¤ì¤¿½çÈÖ¤Ëʤó¤Ç¤¤¤¿ itemInventryDatasList ÊÑ¿ô¤ÎÍ×ÁǤò¡¢°ÊÁ°¥²¡¼¥àÆâ¤Çʤó¤Ç¤¤¤¿¥¢¥¤¥Æ¥à¤Î½çÈ֤˥½¡¼¥È¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£
»²¹Í¥µ¥¤¥È
MicroSoft C# ¥É¥¥å¥á¥ó¥È
Enumerable.OrderBy ¥á¥½¥Ã¥É
https://docs.microsoft.com/ja-jp/dotnet/api/system...
±¢´³¤·Ãæ¤Î¥²¡¼¥à³«È¯¥á¥â ÍÍ
¡ÚC#,LINQ¡ÛOrderBy,OrderByDescending¡ÁÇÛÎó¤ä¥ê¥¹¥È¤òʤÙÂؤ¨¤¿¤¤¤È¤¡Á
https://www.urablog.xyz/entry/2018/06/28/070000
¡¡Ê¸»úÎó¤òƱ¤¸Ì¾¾Î¤Î enum ¤Ë¥¥ã¥¹¥È(·¿ÊÑ´¹)¤·¤Þ¤¹¡£¥¥ã¥¹¥È¤Î·ë²Ì¤ÏÌá¤êÃͤȤ·¤Æ¼èÆÀ¤Ç¤¤Þ¤¹¡£
¡¡¥á¥½¥Ã¥É¤Î½ñ¼°¤Ï [(¥¥ã¥¹¥È¤·¤¿¤¤ enum ¤Î·¿)Enum.Parse(typeof(¥¥ã¥¹¥È¤·¤¿¤¤ enum ¤Î·¿), ¥¥ã¥¹¥È¤¹¤ëʸ»úÎó] ¤Ç¤¹¡£
¡¡
¡¡ÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï using System; ¤ÎÀë¸À¤¬É¬Íפˤʤê¤Þ¤¹¡£
¡¡using System; // ¥»¡¼¥Ö¥Ç¡¼¥¿¤«¤é¥¢¥¤¥Æ¥à¤Î¥Ç¡¼¥¿¤ò¥³¥ó¥¹¥È¥é¥¯¥¿¡¦¥á¥½¥Ã¥É¤òÍøÍѤ·¤ÆÉü¸µ itemInventryDatasList.Add(new ItemInventryData((ItemName)Enum.Parse(typeof(ItemName), stringArray[0]), int.Parse(stringArray[1]), int.Parse(stringArray[2])));
¡¡¾åµ¤Î½èÍý¤Î Add ¥á¥½¥Ã¥É¤ÎÂè1°ú¿ô¤È¤·¤ÆÍøÍѤ·¤Æ¤¤¤Þ¤¹¡£
(ItemName)Enum.Parse(typeof(ItemName), stringArray[0])
¡¡º£²ó¤Î¥±¡¼¥¹¤Ç¤Ï¡¢stringArray[0] ¤ËÂåÆþ¤µ¤ì¤Æ¤¤¤ëʸ»úÎó¤ÎÃͤò¡¢Æ±Ì¾¤Î ItemType ·¿¤ÎÎóµó»Ò¤Ë¥¥ã¥¹¥È¤ò¹Ô¤¦¤È¤¤¤¦½èÍý¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
Î㤨¤Ð¡¢stringArray[0] ¤ÎÍ×ÁǤ¬ "¥Ö¥ë¡¼¥ê¥Ü¥ó" ¤È¤¤¤¦Ê¸»úÎó¤Ç¤¢¤ì¤Ð¡¢ItemType ·¿¤Ë¤¢¤ëÎóµó»Ò¤Î ¥Ö¥ë¡¼¥ê¥Ü¥ó ¤È¤¤¤¦¾ðÊó¤ËÊÑ´¹¤ò¹Ô¤¦½èÍý¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡Îã³°½èÍý(enum ¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤Ê¤¤Ê¸»úÎó¤ò enum ¤ËÊÑ´¹¤·¤è¤¦¤È¤·¤¿¾ì¹ç)¤Ë¤Ï¥¨¥é¡¼¤¬½Ð¤Æ½èÍý¤¬¥¹¥È¥Ã¥×¤·¤Þ¤¹¤Î¤Ç¡¢
Enum.TryParse ¥á¥½¥Ã¥É¤òÍøÍѤ¹¤ë¤³¤È¤Ç¤è¤ê°ÂÁ´¤Ë¥¥ã¥¹¥È¤¬²Äǽ¤Ë¤Ê¤ê¤Þ¤¹¡£
»²¹Í¥µ¥¤¥È
DOBON.NET ÍÍ
¿ôÃͤäʸ»úÎó¤òÎóµóÂΤËÊÑ´¹¤¹¤ë
https://dobon.net/vb/dotnet/programing/enumparse.h...
Qiita @TomoProg ÍÍ
¡ÚC#¡Ûʸ»úÎó¤Èenum¤ÎÊÑ´¹¥Æ¥¯¥Ë¥Ã¥¯½¸
https://qiita.com/TomoProg/items/061861c784853b587...
MicroSoft C# ¥É¥¥å¥á¥ó¥È
Enum.TryParse ¥á¥½¥Ã¥É
https://docs.microsoft.com/ja-jp/dotnet/api/system...
¡¡Ê¸»úÎó¤ò¿ôÃͤ˥¥ã¥¹¥È(·¿ÊÑ´¹)¤¹¤ëµ¡Ç½¤Ë¤Ê¤ê¤Þ¤¹¡£¥¥ã¥¹¥È¤Î·ë²Ì¤ÏÌá¤êÃͤȤ·¤Æ¼èÆÀ¤Ç¤¤Þ¤¹¡£
¿ôÃͤη¿¤Ç¤¢¤ë int, long, float, double ¤Î³Æ·¿¤´¤È¤Ë Parse ¥á¥½¥Ã¥É¤È¡¢Convert ¥á¥½¥Ã¥É¤¬¤¢¤ê¤Þ¤¹¡£¤Þ¤¿¡¢Enum.Parse ¥á¥½¥Ã¥É¤ÈƱ¤¸¤è¤¦¤Ë TryParse ¥á¥½¥Ã¥É¤â¤¢¤ê¤Þ¤¹¡£
// ¥»¡¼¥Ö¥Ç¡¼¥¿¤«¤é¥¢¥¤¥Æ¥à¤Î¥Ç¡¼¥¿¤ò¥³¥ó¥¹¥È¥é¥¯¥¿¡¦¥á¥½¥Ã¥É¤òÍøÍѤ·¤ÆÉü¸µ itemInventryDatasList.Add(new ItemInventryData((ItemName)Enum.Parse(typeof(ItemName), stringArray[0]), int.Parse(stringArray[1]), int.Parse(stringArray[2])));
¡¡¾åµ¤Î½èÍý¤Î Add ¥á¥½¥Ã¥É¤ÎÂè2°ú¿ô¤ÈÂè3°ú¿ô¤·¤ÆÍøÍѤ·¤Æ¤¤¤Þ¤¹¡£
int.Parse(stringArray[1]) ¡¡int.Parse(stringArray[2])
¡¡°ú¿ô¤Ç»ØÄꤷ¤Æ¤¤¤ëʸ»úÎó¤ò¿ô»ú¤Î·¿(º£²ó¤Ï int ·¿)¤Ë¥¥ã¥¹¥È¤·¤ÆÂåÆþ¤·¤Þ¤¹¡£
Î㤨¤Ð¡¢stringArray[1] ÊÑ¿ô¤ÎÍ×ÁǤ¬ "1" ¤È¤¤¤¦Ê¸»úÎó¤Ç¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢ int ·¿¤Î 1 ¤È¤¤¤¦¾ðÊó¤ËÊÑ´¹¤µ¤ì¤Þ¤¹¡£
MicroSoft C# ¥É¥¥å¥á¥ó¥È
ʸ»úÎó¤ò¿ôÃͤËÊÑ´¹¤¹¤ëÊýË¡ (C# ¥×¥í¥°¥é¥ß¥ó¥° ¥¬¥¤¥É)
https://docs.microsoft.com/ja-jp/dotnet/csharp/pro...
¤ï¤ì¤³ ¤ï¤ì¤³ÍÍ
¡Ú¥ï¥ì¥³¤Î¹ÖºÂ¡ÛC#¤Îint.Parse¤ÈConvert.ToInt32¤Î°ã¤¤¤ò¥Þ¥¹¥¿¡¼¡Ú´°àú¤ä¡Û
https://www.wareko.jp/blog/master-difference-betwe...
SAMURAI ¥¨¥ó¥¸¥Ë¥¢¥Ö¥í¥° ÍÍ
¡ÚC#ÆþÌç¡Ûʸ»úÎó¤ò¿ôÃͤˡ¢¿ôÃͤòʸ»úÎó¤ËÊÑ´¹¤¹¤ëÊýË¡
https://www.sejuku.net/blog/44977
¡¡¥»¡¼¥Ö¤·¤¿ÆâÍƤòÇÄ°®¤·¤Æ¤ª¤¤¤Æ¤«¤é¡¢GameData ¥²¡¼¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¤¥ó¥¹¥Ú¥¯¥¿¡¼¤«¤é½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î¾ðÊó¤ò¥ê¥»¥Ã¥È¤·¤Æ¤¯¤À¤µ¤¤¡£
¥¤¥ó¥¹¥Ú¥¯¥¿¡¼²èÁü
¡¡¤³¤Î¾õÂ֤ˤ·¤Æ¤«¤é¥²¡¼¥à¤ò¼Â¹Ô¤·¤Æ¡¢¥í¡¼¥ÉÍѤΥܥ¿¥ó¤ò²¡¤·¤Æ¥í¡¼¥É½èÍý¤ò¹Ô¤Ã¤Æ¤¯¤À¤µ¤¤¡£
Àè¤Û¤É¥ê¥»¥Ã¥È¤·¤¿½ê»ý¥¢¥¤¥Æ¥à¤Î¾ðÊ󤬥»¡¼¥Ö¤·¤Æ¤ª¤¤¤¿¾õÂ֤ˤʤꡢ½ê»ý¥¢¥¤¥Æ¥à¤Îʤӽç¤â´Þ¤á¤ÆÉü¸µ¤Ç¤¤Æ¤¤¤ì¤ÐÀ©¸æÀ®¸ù¤Ç¤¹¡£
¡ã¼ÂÁõ²èÁü¡¡¥í¡¼¥É¡ä
Æ°²è¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯
¡¡°Ê¾å¤Ç¤³¤Î¼ê½ç¤Ï½ªÎ»¤Ç¤¹¡£
¡¡¼¡¤Ï¡¡¼ê½ç£²£³¡¡¡Ý½ê»ý¤·¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤ÎÄɲᦺï½üµ¡Ç½¤ÎÄɲáݡ¡¤Ç¤¹¡£
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- ¥×¥í¥°¥é¥ß¥ó¥°
¥³¥á¥ó¥È¤ò¤«¤¯