{"id":104,"date":"2021-05-19T16:26:35","date_gmt":"2021-05-19T07:26:35","guid":{"rendered":"https:\/\/naoya-ono.com\/unity\/?p=104"},"modified":"2021-05-19T16:28:12","modified_gmt":"2021-05-19T07:28:12","slug":"player-prefs","status":"publish","type":"post","link":"https:\/\/naoya-ono.com\/unity\/player-prefs\/","title":{"rendered":"\u3010Unity\u3011\u30bb\u30fc\u30d6\u3068\u30ed\u30fc\u30c9\u306e\u3084\u308a\u65b9"},"content":{"rendered":"\n<p>\u30b2\u30fc\u30e0\u306e\u30b9\u30b3\u30a2\u3084\u30b9\u30c6\u30fc\u30b8\u306a\u3069\u3092\u300c\u30bb\u30fc\u30d6\u300d\u3057\u305f\u308a\u300c\u30ed\u30fc\u30c9\u300d\u3057\u305f\u308a\u3059\u308b\u306b\u306f\u300c<strong>PlayerPrefs<\/strong>\u300d\u3092\u4f7f\u3046\u3068\u4fbf\u5229\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-sgb-headings sgb-heading\"><div class=\"sgb-heading__inner hh hh17\" style=\"font-size:1.2em\"><span class=\"sgb-heading__text\">1. \u30bb\u30fc\u30d6\u306e\u3084\u308a\u65b9<\/span><\/div><\/h2>\n\n\n\n<p>\u4fdd\u5b58\u3067\u304d\u308b\u578b\u306f\u3001int\u578b\u3001float\u578b\u3001String\u578b\u306e\uff13\u7a2e\u985e\u3067\u3001\u6b21\u306e\u3088\u3046\u306b\u66f8\u304f\u3068\u4fdd\u5b58\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/ \u30bb\u30fc\u30d6\u306e\u3084\u308a\u65b9\n\/\/ 1.\u5024\u3092\u30bb\u30c3\u30c8\nPlayerPrefs.SetInt(&quot;\u30ad\u30fc\u5024&quot; , \u4fdd\u5b58\u3057\u305f\u3044\u5024); \/\/ int\u578b\u306e\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3057\u305f\u3044\u5834\u5408\nPlayerPrefs.SetFloat(&quot;\u30ad\u30fc\u5024&quot; , \u4fdd\u5b58\u3057\u305f\u3044\u5024); \/\/ float\u578b\u306e\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3057\u305f\u3044\u5834\u5408\nPlayerPrefs.SetString(&quot;\u30ad\u30fc\u5024&quot;,&quot; \u4fdd\u5b58\u3057\u305f\u3044\u5024); \/\/ String\u578b\u306e\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3057\u305f\u3044\u5834\u5408\n\n\/\/ 2. \u30c7\u30a3\u30b9\u30af\u3078\u306e\u66f8\u304d\u8fbc\u307f\nPlayerPrefs.Save();\n\n\/\/ \u4f8b\nPlayerPrefs.SetInt(&quot;SCORE&quot; , 130);\nPlayerPrefs.SetFloat(&quot;TIME&quot;, 10.0f);\nPlayerPrefs.SetString(&quot;PLAYER&quot;, &quot;Tokyo Taro&quot;);\nPlayerPrefs.Save();<\/code><\/pre><\/div>\n\n\n\n<p>\u53b3\u5bc6\u306b\u306fSetInt()\u3001SetFloat()\u3001SetString()\u3060\u3051\u3067\u3082\u30c7\u30fc\u30bf\u306e\u4fdd\u5b58\u306f\u53ef\u80fd\u3067\u3059\u304c\u3001\u3053\u308c\u3060\u3051\u3067\u3059\u3068\u3001\u30a2\u30d7\u30ea\u3092\u7d42\u4e86\u3057\u305f\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u30c7\u30fc\u30bf\u304c\u4fdd\u5b58\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u306e\u305f\u3081\u3001\u30a2\u30d7\u30ea\u304c\u9014\u4e2d\u3067\u30af\u30e9\u30c3\u30b7\u30e5\u3057\u3066\u3057\u307e\u3063\u305f\u5834\u5408\u3084\u6b63\u5e38\u306b\u7d42\u4e86\u3057\u306a\u304b\u3063\u305f\u5834\u5408\u306f\u4fdd\u5b58\u3055\u308c\u306a\u3044\u305f\u3081\u3001\u78ba\u5b9f\u306b\u30bb\u30fc\u30d6\u3092\u884c\u3044\u305f\u3044\u5834\u5408\u306f\u3001Save()\u3092\u884c\u3046\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30bb\u30fc\u30d6\u30c7\u30fc\u30bf\u306f\u7aef\u672b\u4e0a\u306b\u4fdd\u5b58\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-sgb-headings sgb-heading\"><div class=\"sgb-heading__inner hh hh17\" style=\"font-size:1.2em\"><span class=\"sgb-heading__text\">2. \u30ed\u30fc\u30c9\u306e\u3084\u308a\u65b9<\/span><\/div><\/h2>\n\n\n\n<p>\u30ed\u30fc\u30c9\u3059\u308b\u306b\u306fget\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/ int\nint score = PlayerPrefs.GetInt(&quot;SCORE&quot;);\n\n\/\/ float\nfloat time = PlayerPrefs.GetFloat(&quot;TIME&quot;);\n\n\/\/ string\nstring name = PlayerPrefs.GetString(&quot;PLAYER&quot;);<\/code><\/pre><\/div>\n\n\n\n<p>\u5024\u304c\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306b\u521d\u671f\u5024\u3092\u30bb\u30c3\u30c8\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u7b2c\u4e8c\u5f15\u6570\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>int score = PlayerPrefs.GetInt(&quot;SCORE&quot;, 0); \/\/ \u4fdd\u5b58\u30c7\u30fc\u30bf\u304c\u306a\u3044\u5834\u5408\u306f0\u3092\u30bb\u30c3\u30c8<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-sgb-headings sgb-heading\"><div class=\"sgb-heading__inner hh hh17\" style=\"font-size:1.2em\"><span class=\"sgb-heading__text\">3. \u524a\u9664\u306e\u3084\u308a\u65b9<\/span><\/div><\/h2>\n\n\n\n<p>\u30bb\u30fc\u30d6\u3057\u305f\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u6b21\u306e\u3088\u3046\u306b\u66f8\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>PlayerPrefs.DeleteKey(&quot;\u4fdd\u5b58\u6642\u306b\u3057\u3066\u3057\u305f\u30ad\u30fc&quot;);<\/code><\/pre><\/div>\n\n\n\n<p>\u5168\u3066\u306e\u30c7\u30fc\u30bf\u3092\u4e00\u5ea6\u306b\u524a\u9664\u3057\u305f\u3044\u5834\u5408\u306f\u3001DelerteAll()\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>PlayerPrefs.DeleteAll();<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u30b2\u30fc\u30e0\u306e\u30b9\u30b3\u30a2\u3084\u30b9\u30c6\u30fc\u30b8\u306a\u3069\u3092\u300c\u30bb\u30fc\u30d6\u300d\u3057\u305f\u308a\u300c\u30ed\u30fc\u30c9\u300d\u3057\u305f\u308a\u3059\u308b\u306b\u306f\u300cPlayerPrefs\u300d\u3092\u4f7f\u3046\u3068\u4fbf\u5229\u3067\u3059\u3002 \u4fdd\u5b58\u3067\u304d\u308b\u578b\u306f\u3001int\u578b\u3001float\u578b\u3001String\u578b\u306e\uff13\u7a2e\u985e\u3067\u3001\u6b21\u306e\u3088\u3046\u306b\u66f8\u304f\u3068\u4fdd\u5b58\u3067\u304d\u307e\u3059\u3002 \u53b3\u5bc6\u306b &#8230; <\/p>\n","protected":false},"author":1,"featured_media":108,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":{"0":"post-104","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-coding"},"_links":{"self":[{"href":"https:\/\/naoya-ono.com\/unity\/wp-json\/wp\/v2\/posts\/104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/naoya-ono.com\/unity\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/naoya-ono.com\/unity\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/unity\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/unity\/wp-json\/wp\/v2\/comments?post=104"}],"version-history":[{"count":5,"href":"https:\/\/naoya-ono.com\/unity\/wp-json\/wp\/v2\/posts\/104\/revisions"}],"predecessor-version":[{"id":110,"href":"https:\/\/naoya-ono.com\/unity\/wp-json\/wp\/v2\/posts\/104\/revisions\/110"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/unity\/wp-json\/wp\/v2\/media\/108"}],"wp:attachment":[{"href":"https:\/\/naoya-ono.com\/unity\/wp-json\/wp\/v2\/media?parent=104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/naoya-ono.com\/unity\/wp-json\/wp\/v2\/categories?post=104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/naoya-ono.com\/unity\/wp-json\/wp\/v2\/tags?post=104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}