ºÇ½ª¹¹¿·¡§ orika_ex_miyako 2022ǯ03·î23Æü(¿å) 17:39:40ÍúÎò
¡ã¼ÂÁõÆ°²è¡ä
Æ°²è¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯
¡¡¿·¤·¤¤³Ø½¬ÆâÍƤϰʲ¼¤ÎÄ̤ê¤Ç¤¹¡£
¡¡¡¦PlayerPrefs ¥¯¥é¥¹¤È³Æ¥á¥½¥Ã¥É¡¡¡¼Set¡Á ¥á¥½¥Ã¥É¡¢Save ¥á¥½¥Ã¥É¡¢Get¡Á ¥á¥½¥Ã¥É¡¢HasKey ¥á¥½¥Ã¥É¡¢DeleteAll ¥á¥½¥Ã¥É¡¼
¡¡¥¤¥ó¥Ù¥ó¥È¥ê¤Ë´ÉÍý¤µ¤ì¤Æ¤¤¤ë½ê»ý¡Ê³ÍÆÀ¡Ë¥¢¥¤¥Æ¥à¤Î¾ðÊó¤ò¥»¡¼¥Ö¡¦¥í¡¼¥É¤¹¤ëµ¡Ç½¤ò¼ÂÁõ¤·¤Þ¤¹¡£
¡¡¤Þ¤º¤Ï¥µ¡¼¥Ð¡¼¤Ø¤Î¥»¡¼¥Ö¡¦¥í¡¼¥É¤Ç¤Ï¤Ê¤¯¡¢Unity ¤Î PlayerPrefs ¥¯¥é¥¹¤òÍøÍѤ·¡¢¥Ç¥Ð¥¤¥¹Æâ¤Ë¥»¡¼¥Ö¤·¤Æ¡¢¤½¤Î¥Ç¡¼¥¿¤ò¥í¡¼¥É¤¹¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£
¤½¤ì¤¬ÌäÂê¤Ê¤¯Æ°ºî¤¹¤ë¤³¤È¤¬³Îǧ¤Ç¤¤Æ¤«¤é¡¢¥µ¡¼¥Ð¡¼¤Ç¤Î¥»¡¼¥Ö¡¦¥í¡¼¥É¤ò¸¡Æ¤¤·¤Þ¤¹¡£
¡¡PlayerPrefs ¥¯¥é¥¹¤Ç¥Ç¡¼¥¿¤ò¥»¡¼¥Ö¡¦¥í¡¼¥É¤¹¤ëºÝ¤Ë¤Ï¡¢Êݸ¤¬²Äǽ¤Ê·¿¤È¡¢¤½¤Î¾ðÊó¤òÊݸ¤¹¤ë¤¿¤á¤Î Key ¤Î¾ðÊó¤¬É¬Íפˤʤê¤Þ¤¹¡£
Key ¤Ï string ·¿¤Ç»ØÄꤷ¤Þ¤¹(Key ¤Ï¥é¥Ù¥ë¤Î¤è¤¦¤Ê¤â¤Î¤Ç¤¢¤ê¡¢Ì¾Á°¤òÉÕ¤±¤ÆÊݸ¤¹¤ë¥¤¥á¡¼¥¸¤Ç¤¹)¡£
¡¡¤½¤Î¤¿¤áº£²ó¤Ï¡¢ItemData ¥¯¥é¥¹¤Ë¤¢¤ë string ·¿¤Î itemName ÊÑ¿ô¤ò Key ¤ËÍøÍѤ·¡¢¤½¤Î¥¢¥¤¥Æ¥à¤Î½ê»ý¿ô(int ·¿)¤ò¥»¡¼¥Ö¡¦¥í¡¼¥É¤·¤Þ¤¹¡£
itemName ÊÑ¿ô¤ÏÊݸ¤¹¤ë¤¿¤á¤Î¥é¥Ù¥ë¤ÎÌò³ä¤È¥¢¥¤¥Æ¥à¤Î¼ïÎà¤òÆÃÄꤹ¤ë¤¿¤á¤Î£²¤Ä¤ÎÌÜŪ¤ËÍøÍѤ·¤Æ¤¤¤Þ¤¹¡£
¡¡¥¤¥ó¥Ù¥ó¥È¥êµ¡Ç½¤Ï GameData ¥¯¥é¥¹¤Ç´ÉÍý¤µ¤ì¤Æ¤¤¤ë¤¿¤á¡¢¥»¡¼¥Ö¡¦¥í¡¼¥É¤Îµ¡Ç½¤âƱ¤¸¤¯ GameData ¥¯¥é¥¹Æâ¤Ë¿·¤·¤¯ºîÀ®¤·¤Þ¤¹¡£
¹ç¤ï¤»¤Æ¡¢¥¢¥¤¥Æ¥à¤Î»ý¤Ä¥¹¥³¥¢¤Î¹ç·×Ãͤʤɤò·×»»¤¹¤ëµ¡Ç½¤â¼ÂÁõ¤·¤Æ¤ª¤¤Þ¤¹¡£
¡¡¥»¡¼¥Ö¡¦¥í¡¼¥É¤Îµ¡Ç½¤ò¥á¥½¥Ã¥É¤È¤·¤ÆºîÀ®¤·¤Æ¤ª¤¯¤³¤È¤Ç¡¢¤¤¤º¤ì¤Î¥¯¥é¥¹¤«¤é¤Ç¤â¥»¡¼¥Ö¡¦¥í¡¼¥É¤Îµ¡Ç½¤ò¼Â¹Ô¤Ç¤¤ë¤è¤¦¤Ë¤·¤Æ¤¤¤Þ¤¹¡£
º£²ó¤Ï¤Þ¤º¡¢Â¾¤Î¥¯¥é¥¹¤Ë¥á¥½¥Ã¥É¤Î¼Â¹ÔÌ¿Îá¤òµ½Ò¤·¤Ê¤¯¤Æ¤â¥Ç¥Ð¥Ã¥°¤¬¹Ô¤¨¤ë¤è¤¦¤Ë¡¢¿·¤·¤¯ Update ¥á¥½¥Ã¥É¤òÄɲä·¡¢
¥Ü¥¿¥óÁàºî»þ¤Ë¥»¡¼¥Ö¡¦¥í¡¼¥É¤Îµ¡Ç½¤ò¼Â¹Ô¤Ç¤¤ë¤è¤¦¤Ë¤·¤Æ¤¤¤Þ¤¹¡£
¡¡¤³¤¦¤¤¤Ã¤¿¥Ç¥Ð¥Ã¥°µ¡Ç½¤â¼«Ê¬¤ÇÀ߷פ·¤ÆÍÑ°Õ¤·¤Æ¤ª¤±¤ë¤è¤¦¤Ë¹Í¤¨¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
GameData.cs
¡ãPlayerPrefs ¥¯¥é¥¹¤È³Æ¥á¥½¥Ã¥É¡¡¡¼Set¡Á ¥á¥½¥Ã¥É¡¢Save ¥á¥½¥Ã¥É¡¢Get¡Á ¥á¥½¥Ã¥É¡¢HasKey ¥á¥½¥Ã¥É¡¢DeleteAll ¥á¥½¥Ã¥É¡ä
¡¡Unity ¤Ç¤Ï¥Ç¡¼¥¿¤Î¥»¡¼¥Ö¡¦¥í¡¼¥É¤ò¹Ô¤¦¤¿¤á¤Î PlayerPrefs ¥¯¥é¥¹¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
PlayerPrefs ¥¯¥é¥¹¤Ë¤Ï¥»¡¼¥Ö¡¦¥í¡¼¥ÉÍѤΥ᥽¥Ã¥É¤ä¡¢¥Ç¡¼¥¿¤Î³Îǧ¥á¥½¥Ã¥É¡¢ºï½üÍѤΥ᥽¥Ã¥É¤Ê¤É¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢
¤³¤Á¤é¤ò¼ÂÁõ¤¹¤ë¤³¤È¤Ç»ØÄꤷ¤¿¥Ç¡¼¥¿¤ò¥»¡¼¥Ö¤·¤¿¤ê¡¢¥í¡¼¥É¤·¤¿¤ê¤¹¤ë¤³¤È¤¬²Äǽ¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
¡¡¥Ç¡¼¥¿¤ÎÊݸÀè¤Ï¡¢Unity Editor ¤ä PC ¥²¡¼¥à¤Î¾ì¹ç¤Ë¤Ï PC ËÜÂΤΥϡ¼¥É¥Ç¥£¥¹¥¯¡¢Web ¤Î¾ì¹ç¤Ï¥Ö¥é¥¦¥¶Æâ¡¢¥¹¥Þ¥ÛüËö¤Î¾ì¹ç¤Ë¤Ï¥¢¥×¥êÆâ¤Î¥Ç¡¼¥¿¤Î¾ì½êÆâ¤Ç¤¹¡£
VR ¤Î¾ì¹ç¤Ë¤Ï¡¢¥ª¥¥å¥é¥¹¥¯¥¨¥¹¥È¤Î¥Ç¥Ð¥¤¥¹Æâ¤Ë¤Ê¤ê¤Þ¤¹¡£
¡ãPlayerPrefs ¥¯¥é¥¹¡ä
https://docs.unity3d.com/ja/current/ScriptReferenc...
¡¡£²¤Ä¤Î¥á¥½¥Ã¥É¤òÍøÍѤ·¤Æ¥»¡¼¥Ö¤ò¹Ô¤¤¤Þ¤¹¤Î¤Ç¡¢½çÈÖ¤ËÀâÌÀ¤·¤Þ¤¹¡£
¡¡Key ¤È¤¤¤¦Ê¸»úÎó¤òÊݸ¤¹¤ëºÝ¤Î¼±Ê̻ҤȤ·¤Æ»ØÄꤷ¡¢¤½¤Î̾Á°¤òÍѤ¤¤Æ»ØÄꤵ¤ì¤¿·¿¤Î¾ðÊó¤ò¥»¡¼¥Ö¤¹¤ë¤¿¤á¤Î½àÈ÷(ͽÌó)¤ò¹Ô¤¤¤Þ¤¹¡£
Key ¤È¤Ï¤¤¤ï¤Ð¥»¡¼¥ÖÍѤΥé¥Ù¥ë¤Ç¤¢¤ê¡¢Ì¾Á°¤òÉÕ¤±¤ÆÊݸ¤Î¤³¤È¤Ç¤¹¡£¤³¤Î Key ¤Î¾ðÊó¤ò¥í¡¼¥É¤¹¤ëºÝ¤Ë¤âÍøÍѤ·¤Þ¤¹¡£
¡¡PlayerPrefs ¥¯¥é¥¹¤Ë¤Ï¥»¡¼¥Ö¤ÎÊýË¡¤¬£³¼ïÎàÍÑ°Õ¤µ¤ì¤Æ¤ª¤ê¡¢Set ¡Á ¤Ç»Ï¤Þ¤ë̿̾µ¬Â§¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£º£²óÍøÍѤ·¤Æ¤¤¤ë SetInt ¥á¥½¥Ã¥É¤â¤½¤Î£±¤Ä¤Ç¤¹¡£
SetInt ¤È¤¤¤¦Ì¾Á°¤ÎÄ̤ꡢint ·¿¤Î¾ðÊó¤ò¥»¡¼¥Ö¤·¤Æ¤ª¤¯¤³¤È¤¬½ÐÍè¤Þ¤¹¡£»Ä¤ë£²¤Ä¤Ï SetString ¥á¥½¥Ã¥É¡¢SetFloat ¥á¥½¥Ã¥É¤Ç¤¢¤ê¡¢¤³¤ì¤é¤â¥á¥½¥Ã¥É̾¤ÈƱ̾¤Î·¿¤Î¾ðÊó¤ò¥»¡¼¥Ö¤·¤Þ¤¹¡£
¡¡º£²ó¥»¡¼¥Ö¤·¤¿¤¤¾ðÊó¤Ï GameData ¥¯¥é¥¹¤Ç´ÉÍý¤·¤Æ¤¤¤ë InventryData ¥¯¥é¥¹¤Î int ·¿¤Î itemCount ÊÑ¿ô¤Ç¤¹¡£¤Ä¤Þ¤ê¡¢»ØÄꤵ¤ì¤¿¥¢¥¤¥Æ¥à¤Î½ê»ý¿ô¤Ç¤¹¡£
int ·¿¤Î¾ðÊó¤Ç¤¢¤ì¤Ð SetInt ¥á¥½¥Ã¥É¤ò¼Â¹Ô¤¹¤ë¤³¤È¤Ç¡¢¥»¡¼¥Ö¤Î½àÈ÷(ͽÌó)¤¬¤Ç¤¤Þ¤¹¡£
¡¡for (int i = 0; i < inventryDatasList.Count; i++) { ¡¡¡¡PlayerPrefs.SetInt(inventryDatasList[i].itemData.itemName, inventryDatasList[i].itemCount); }
¡¡SetInt ¥á¥½¥Ã¥É¤ÎÂè1°ú¿ô¤¬ Key ¤Ë¤Ê¤ê¤Þ¤¹¡£¥á¥½¥Ã¥É¤Î°ú¿ô¤ÇÆϤ¤¤Æ¤¤¤ë key ¤Î¾ðÊó¤ò¤½¤Î¤Þ¤ÞÍøÍѤ·¤Æ¤¤¤Þ¤¹¡£
¡¡SetInt ¥á¥½¥Ã¥É¤ÎÂè2°ú¿ô¤¬¥»¡¼¥Ö¤µ¤ì¤ëÃÍ(int ·¿)¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡Set ¡Á ¤Ç»Ï¤Þ¤ë£³¤Ä¤Î¥á¥½¥Ã¥É¤Ï¡¢¥»¡¼¥Ö¤ò¹Ô¤¦ÂоݤòÀßÄꤷ¤Æ¤¤¤Þ¤¹¡£¤½¤Î¤¿¤á¥»¡¼¥Ö¤¹¤ë¤¿¤á¤Î¾ðÊó¤ò¥»¥Ã¥È¤·¤Æ½àÈ÷¤ò¹Ô¤¦¥á¥½¥Ã¥É¤Ç¤¹¡£
¼ÂºÝ¤Ë¤Ï¼¡¤Ë²òÀ⤹¤ë Save ¥á¥½¥Ã¥É¤ò¼Â¹Ô¤¹¤ë¤³¤È¤Ç¥Ç¡¼¥¿¤¬¥»¡¼¥Ö¤µ¤ì¤Þ¤¹¡£
»²¹Í¥µ¥¤¥È
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
PlayerPrefs.SetString
https://docs.unity3d.com/ja/current/ScriptReferenc...
¡¡Set ¡Á ¥á¥½¥Ã¥É¤Ë¤è¤Ã¤Æ½àÈ÷¤µ¤ì¤¿¾ðÊó¤ò¥»¡¼¥Ö¤¹¤ë¥á¥½¥Ã¥É¤Ç¤¹¡£
¤³¤Î½èÍý¤¬¼Â¹Ô¤µ¤ì¤Æ»Ï¤á¤Æ¥Ç¡¼¥¿¤¬¥»¡¼¥Ö¤µ¤ì¤Þ¤¹¡£
¡¡Save ¥á¥½¥Ã¥É¤è¤ê¤âÁ°¤Ë¡¢Ê£¿ô¤Î Set ¡Á ¥á¥½¥Ã¥É¤¬¼Â¹Ô¤µ¤ì¤Æ¤¤¤¿¾ì¹ç¡¢¤³¤Î Save ¥á¥½¥Ã¥É¤Ï¤½¤ì¤é¤¹¤Ù¤Æ¤Î Set ¡Á ¥á¥½¥Ã¥É¤Î¥»¡¼¥Ö¤ò¹Ô¤¤¤Þ¤¹¡£
¡¡// ¥¢¥¤¥Æ¥à¤Î¿ô¤À¤±¡¢¥»¡¼¥Ö¤Î½àÈ÷ for (int i = 0; i < inventryDatasList.Count; i++) { ¡¡¡¡PlayerPrefs.SetInt(inventryDatasList[i].itemData.itemName, inventryDatasList[i].itemCount); } // ¥»¡¼¥Ö¼Â¹Ô(½àÈ÷¤·¤¿ SetInt ¥á¥½¥Ã¥É¤ÎÆâÍƤ¬¤¹¤Ù¤Æ£±²ó¤Ç¥»¡¼¥Ö¤µ¤ì¤ë) PlayerPrefs.Save();
¡¡º£²ó¤Î¾ì¹ç¤Ë¤Ï¡¢int ·¿¤ÎÀ°¿ô¤Î¾ðÊó¤ò¥»¡¼¥Ö¤·¤Æ¤¤¤Þ¤¹¡£
Save ¥á¥½¥Ã¥É¤Î¼Â¹Ô²ó¿ô¤Ï£±²ó¤Ç¤¹¤¬¡¢SetInt ¥á¥½¥Ã¥É¤Ï¥¢¥¤¥Æ¥à¤Î¼ïÎàʬ¤À¤±¼Â¹Ô¤µ¤ì¤Æ¡¢¤½¤ì¤¾¤ì¤Î¥Ç¡¼¥¿¤È¤·¤ÆÊÝ»ý¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
¤Ä¤Þ¤ê¡¢£±¤Ä¤Î¥Ç¡¼¥¿¤È¤·¤Æ¥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤ëÌõ¤Ç¤Ï¤Ê¤¯¡¢¸Ä¡¹¤Î¥¢¥¤¥Æ¥à¤´¤È¤Ë£±¤Ä¤º¤Ä¤Î¥»¡¼¥Ö¥Ç¡¼¥¿¤¬ºî¤é¤ì¤Æ¤¤¤Þ¤¹¡£
»²¹Í¥µ¥¤¥È
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
PlayerPrefs.Save
https://docs.unity3d.com/ja/current/ScriptReferenc...
¡¡PlayerPrefs ¥¯¥é¥¹¤ËÍÑ°Õ¤µ¤ì¤Æ¤¤¤ë¡¢¥í¡¼¥ÉÍѤΥ᥽¥Ã¥É¤Ç¤¹¡£Set ¡Á ¥á¥½¥Ã¥É¤ËÂбþ¤Ç¤¤ë¤è¤¦¤Ë¡¢¤³¤Á¤é¤Ë¤â£³¤Ä¤Î¥á¥½¥Ã¥É¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
º£²ó¤Ï SetInt ¥á¥½¥Ã¥É¤Ç int ·¿¤Î¾ðÊó¤ò¥»¡¼¥Ö¤·¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢¥í¡¼¥É¤¹¤ë¾ì¹ç¤Ë¤Ï¡¢GetInt ¥á¥½¥Ã¥É¤òÍøÍѤ·¤Æ¹Ô¤¤¤Þ¤¹¡£
¡¡Get ¡Á ¥á¥½¥Ã¥É¤ÎÂè1°ú¿ô¤Ë¤Ï¡¢Key ¤ò»ØÄꤷ¤Þ¤¹¡£
PlayerPrefs Æâ¤Ë¥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤ë Key ¤¬Â¸ºß¤·¤Æ¤¤¤ë¤«¤ò¸¡º÷¡¦¾È¹ç¤·¡¢Key ¤¬Â¸ºß¤·¤Æ¤¤¤ë¾ì¹ç¡¢¤½¤Î¾ðÊó¤ò»ØÄꤷ¤¿·¿¤Ç¼èÆÀ¤¹¤ë¥á¥½¥Ã¥É¤Ç¤¹¡£
¼èÆÀ¤·¤¿ÃͤÏÌá¤êÃͤȤ·¤ÆÄ󶡤µ¤ì¤Þ¤¹¡£¤½¤Î¤¿¤á¡¢Get ¡Á ¥á¥½¥Ã¥É¤ò¼Â¹Ô¤¹¤ë¾ì¹ç¤Ë¤Ï¡¢º¸ÊÕ¤ËÌá¤êÃͤò¼õ¤±¼è¤ë¤¿¤á¤ÎÊÑ¿ô¤ò½àÈ÷¤·¤Æ¤ª¤¯É¬Íפ¬¤¢¤ê¤Þ¤¹¡£
º£²ó¤Ï¡¢GetInt ¥á¥½¥Ã¥É¤Ç¤¹¤Î¤Ç¡¢¥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤ë Key ¤¬Â¸ºß¤·¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¢int ·¿¤Ç¼èÆÀ¡¢¤Ä¤Þ¤ê¥í¡¼¥É¤ò¹Ô¤¦½èÍý¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡Get ¡Á ¥á¥½¥Ã¥É¤ÏÂè2°ú¿ô¤òÀßÄꤹ¤ë¤³¤È¤Ç¡¢¤â¤·¤â Key ¤¬Â¸ºß¤·¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¡¢Âè2°ú¿ô¤Ë»ØÄꤷ¤¿Ãͤò Default ÃͤȤ·¤ÆÀßÄê¤ò¹Ô¤¦¤³¤È¤â½ÐÍè¤Þ¤¹¡£
¡¡
¡¡// ¥¤¥ó¥Ù¥ó¥È¥ê¤Ë¥¢¥¤¥Æ¥à¤Î¥Ç¡¼¥¿¤òÄɲä·¤ÆÉü¸µ AddIndentryDatasList(PlayerPrefs.GetInt(DataBaseManager.instance.itemDataSO.itemDatasList[i].itemName, 0), itemData);
¡¡¾åµ½èÍý¤Î¤¦¤Á¡¢°ú¿ôÆâ¤Î
¡¡PlayerPrefs.GetInt(DataBaseManager.instance.itemDataSO.itemDatasList[i].itemName) ¡¡¤³¤ÎÉôʬ¤¬¥Ç¡¼¥¿¤Î¥í¡¼¥É¤ò¤·¤Æ¤¤¤ëÉôʬ
¡¡GetInt ¥á¥½¥Ã¥É¤Ç¼èÆÀ¤·¤¿¾ðÊó¤Ï int ·¿¤Ç¤¹¤Î¤Ç¡¢¤½¤ÎÃͤ¬ itemCount ÊÑ¿ô¤ËÂåÆþ¤µ¤ì¤ë¤³¤È¤Ç¡¢¥í¡¼¥É½èÍý¤ò´°Î»¤·¤Æ¤¤¤Þ¤¹¡£
Âè2°ú¿ô¤Ë 0 ¤òÀßÄꤷ¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢Ëü¤¬°ì¡¢ Key ¤Î¾ðÊ󤬥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢ 0 ¤òÂåÆþ¤¹¤ë½èÍý¤ò¹Ô¤¤¤Þ¤¹¡£
»²¹Í¥µ¥¤¥È
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
PlayerPrefs.GetString
https://docs.unity3d.com/ja/current/ScriptReferenc...
¡¡°ú¿ô¤Ë»ØÄꤷ¤¿Ê¸»úÎó¤¬ PlayerPrefs ¤ËÊݸ¤µ¤ì¤Æ¤¤¤ë Key ¤Î¾ðÊó¤È¤·¤Æ¤¢¤ë¤«¤òÄ´¤Ù¤Æ¡¢Key ¤¬Â¸ºß¤·¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï true¡¢Â¸ºß¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï false ¤òÌᤷ¤Þ¤¹¡£
// ¥¢¥¤¥Æ¥à¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹Æâ¤È¥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤ë¥Ç¡¼¥¿¤Î¥¢¥¤¥Æ¥à¤Î̾Á°¤È¤ò£±¤Ä¤º¤Ä½çÈ֤˾ȹç for (int i = 0; i < DataBaseManager.instance.itemDataSO.itemDatasList.Count; i++) { ¡¡¡¡ ¡¡ // ¥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤ë¾ðÊó¤Ë¥¢¥¤¥Æ¥à¤Î̾Á°¤¬¹çÃפ·¤Æ¤¤¤ë¥Ç¡¼¥¿¤¬¸«¤Ä¤«¤Ã¤¿¾ì¹ç if (PlayerPrefs.HasKey(DataBaseManager.instance.itemDataSO.itemDatasList[i].itemName)) {
¡¡º£²ó¤Î¥±¡¼¥¹¤Ç¤Ï¡¢for ʸÆâ¤Ç if ʸ¤Î¾ò·ï¼°¤È¤·¤Æµ½Ò¤·¤Æ¡¢¥¢¥¤¥Æ¥à¥Ç¡¼¥¿¤Ë¤¢¤ë¥¢¥¤¥Æ¥à¤Î̾Á°¤È¡¢Êݸ¤µ¤ì¤Æ¤¤¤ë¥¢¥¤¥Æ¥à¤Î̾Á°¤¬°ìÃפ¹¤ë¤«¤òȽÄꤷ¤Æ¤¤¤Þ¤¹¡£
¥»¡¼¥Ö¤¹¤ëºÝ¤Î Key ¤Ë¥¢¥¤¥Æ¥à¤Î̾Á°¤òÀßÄꤷ¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢¤½¤Î¸ºß¤¬¤Ê¤¤¾ì¹ç(false)¤È¸ºß¤¹¤ë¾ì¹ç(true)¤È¤Ç°Û¤Ê¤ëÃͤòÌ᤹¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
»²¹Í¥µ¥¤¥È
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
PlayerPrefs.HasKey
https://docs.unity3d.com/ja/current/ScriptReferenc...
¡¡PlayerPrefs Æâ¤Ë¥»¡¼¥Ö¤µ¤ì¤Æ¤¤¤ë¤¹¤Ù¤Æ¤Î¾ðÊó¤ò¤Þ¤È¤á¤Æºï½ü¤¹¤ë¥á¥½¥Ã¥É¤Ç¤¹¡£
¤³¤ÎÁàºî¤Ï Unity ¥¨¥Ç¥£¥¿¡¼¤«¤é¼Â¹Ô¤¹¤ë¤³¤È¤â²Äǽ¤Ç¤¹¡£¼ç¤Ë¥Ç¡¼¥¿¤ò¥ê¥»¥Ã¥È¤¹¤ëºÝ¤ËÍøÍѤ·¤Þ¤¹¤Î¤Ç¡¢
¥²¡¼¥à¤Î¥Ç¡¼¥¿¤ò½é´ü²½¤·¤Æ¥Ç¥Ð¥Ã¥°¤ò¹Ô¤¦ºÝ¤Ë¤âÍøÍѤǤ¤Þ¤¹¡£
¡¡Key ñ°Ì¤Çºï½ü¤¹¤ë DeleteKey ¥á¥½¥Ã¥É¤â¤¢¤ê¤Þ¤¹¡£
¡¡
¡¡// ¤¹¤Ù¤Æ¤Î¥»¡¼¥Ö¥Ç¡¼¥¿¤òºï½ü PlayerPrefs.DeleteAll();
»²¹Í¥µ¥¤¥È
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
PlayerPrefs.DeleteAll
https://docs.unity3d.com/ja/current/ScriptReferenc...
Unity¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
PlayerPrefs.DeleteKey
https://docs.unity3d.com/ja/current/ScriptReferenc...
¡¡°Ê¾å¤Ç¤¹¡£
¼«Í³¤Ë½èÍý¤òºîÀ®¤·¤Æ¡¢¤É¤Î¤è¤¦¤ËÆ°¤¯¤«¤ò³Îǧ¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
¡¡¥²¡¼¥à¤ò¼Â¹Ô¤·¡¢¥¤¥ó¥Ù¥ó¥È¥ê¤ËǤ°Õ¤Î¥¢¥¤¥Æ¥à¤òÄɲä·¤Þ¤¹¡£
¤½¤Î¾õÂ֤ǥ»¡¼¥ÖÍѤΥܥ¿¥ó¤ò²¡¤·¡¢¥²¡¼¥à¤ò½ªÎ»¤·¤Þ¤¹¡£
¡¡ºÆÅÙ¥²¡¼¥à¼Â¹Ô¸å¡¢º£¸å¤Ï¥í¡¼¥ÉÍѤΥܥ¿¥ó¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤¡£
GameData ¤Î¥¤¥ó¥Ù¥ó¥È¥ê¤Ë¥»¡¼¥Ö¤·¤Æ¤ª¤¤¤¿¥Ç¡¼¥¿¤¬¥í¡¼¥É¤µ¤ì¤ÆÉü¸µ¤µ¤ì¤ì¤ÐÀ®¸ù¤Ç¤¹¡£
¥í¡¼¥É¤¹¤ëºÝ¤Ë¤Ï¡¢¥¢¥¤¥Æ¥à¤Î¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¤Î ItemName ÊÑ¿ô¤ÎÃͤȥ»¡¼¥Ö¤·¤Æ¤¤¤ëºÝ¤ËÍøÍѤ·¤Æ¤¤¤ë ItemName ÊÑ¿ô¤ÎÃͤȤò¾È¹ç¤·¤Æ¤¤¤Þ¤¹¡£
¥¢¥¤¥Æ¥à¤Î¿ô¤âÉü¸µ¤µ¤ì¤Æ¤¤¤ë¤³¤È¤ò³Îǧ¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£
¡ã¥»¡¼¥Ö»þ¤Î¥¤¥ó¥Ù¥ó¥È¥ê¡ä
¡ã¥¢¥¤¥Æ¥à¤Î¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¡ä
¡ã¼ÂÁõÆ°²è¡ä
Æ°²è¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯
¡¡°Ê¾å¤Ç¤³¤Î¼ê½ç¤Ï½ªÎ»¤Ç¤¹¡£
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- ¥×¥í¥°¥é¥ß¥ó¥°
¥³¥á¥ó¥È¤ò¤«¤¯