{"id":1000,"date":"2017-02-04T16:31:48","date_gmt":"2017-02-04T08:31:48","guid":{"rendered":"http:\/\/39.100.100.179\/?p=1000"},"modified":"2017-05-09T10:39:45","modified_gmt":"2017-05-09T02:39:45","slug":"%e6%9c%80%e5%a5%bd%e7%94%a8%e7%9a%84%e6%95%b0%e6%8d%ae%e5%ad%98%e5%82%a8easy-save2%e8%ae%b2%e8%a7%a3","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=1000","title":{"rendered":"\u6700\u597d\u7528\u7684\u6570\u636e\u5b58\u50a8Easy Save2\u8bb2\u89e3"},"content":{"rendered":"<p>\u4eca\u5929\u62bd\u65f6\u95f4\u5b66\u4e60\u4e86\u201cEasy Save2\u201d\u63d2\u4ef6\uff0c\u7248\u672cv2.6.3 \u00a0\u6211\u4e2a\u4eba\u89c9\u5f97\u8fd9\u4e2a\u63d2\u4ef6\u662f\u505a\u6570\u636e\u5b58\u53d6\u6700\u597d\u7684\u63d2\u4ef6~~\u53ef\u4ee5\u53d6\u4ee3PlayerPrefs\u3002<\/p>\n<p>\u5b83\u4e0d\u4ec5\u53ef\u4ee5\u76f4\u63a5\u5b58\u53d6PlayerPrefs\u652f\u6301\u7684int\u3001float\u3001string\u3001bool<\/p>\n<p>\u8fd8\u5305\u62ec\u4e0b\u56fe\u4e2d\u6240\u6709\u7c7b\u578b<\/p>\n<p><a href=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/02\/QQ\u622a\u56fe20170204165329.png\" data-lightbox=\"image_lg\"><img title=\"\u6700\u597d\u7528\u7684\u6570\u636e\u5b58\u50a8Easy Save2\u8bb2\u89e3 - \u7b2c1\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"\u6700\u597d\u7528\u7684\u6570\u636e\u5b58\u50a8Easy Save2\u8bb2\u89e3 - \u7b2c1\u5f20  | u3d8\u6280\u672f\u5206\u4eab\"  loading=\"lazy\" class=\"size-full wp-image-1010 alignleft\"  data-src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/02\/QQ\u622a\u56fe20170204165329.png\" width=\"158\" height=\"164\" \/><\/a> <a href=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/02\/QQ\u622a\u56fe20170204165315.png\" data-lightbox=\"image_lg\"><img title=\"\u6700\u597d\u7528\u7684\u6570\u636e\u5b58\u50a8Easy Save2\u8bb2\u89e3 - \u7b2c2\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"\u6700\u597d\u7528\u7684\u6570\u636e\u5b58\u50a8Easy Save2\u8bb2\u89e3 - \u7b2c2\u5f20  | u3d8\u6280\u672f\u5206\u4eab\"  loading=\"lazy\" class=\"size-full wp-image-1009 alignleft\"  data-src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/02\/QQ\u622a\u56fe20170204165315.png\" width=\"152\" height=\"453\" srcset=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/02\/QQ\u622a\u56fe20170204165315.png 152w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/02\/QQ\u622a\u56fe20170204165315-101x300.png 101w\" sizes=\"(max-width: 152px) 100vw, 152px\" \/><\/a> <a href=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/02\/QQ\u622a\u56fe20170204165242.png\" data-lightbox=\"image_lg\"><img title=\"\u6700\u597d\u7528\u7684\u6570\u636e\u5b58\u50a8Easy Save2\u8bb2\u89e3 - \u7b2c3\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"\u6700\u597d\u7528\u7684\u6570\u636e\u5b58\u50a8Easy Save2\u8bb2\u89e3 - \u7b2c3\u5f20  | u3d8\u6280\u672f\u5206\u4eab\"  loading=\"lazy\" class=\"size-full wp-image-1007 alignleft\"  data-src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/02\/QQ\u622a\u56fe20170204165242.png\" width=\"145\" height=\"271\" \/><\/a> <a href=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/02\/QQ\u622a\u56fe20170204165302.png\" data-lightbox=\"image_lg\"><img title=\"\u6700\u597d\u7528\u7684\u6570\u636e\u5b58\u50a8Easy Save2\u8bb2\u89e3 - \u7b2c4\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"\u6700\u597d\u7528\u7684\u6570\u636e\u5b58\u50a8Easy Save2\u8bb2\u89e3 - \u7b2c4\u5f20  | u3d8\u6280\u672f\u5206\u4eab\"  loading=\"lazy\" class=\"size-full wp-image-1008 alignnone\"  data-src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/02\/QQ\u622a\u56fe20170204165302.png\" width=\"208\" height=\"180\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u5982\u679c\u4e0d\u6307\u5b9a\u4f4d\u7f6e\uff0c\u6570\u636e\u4f1a\u5b58\u50a8\u5728Application.persistentDataPath\u91cc<\/p>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u6307\u5b9a\u5b83\u7684\u5b58\u50a8\u4f4d\u7f6e\u00a0\u7c7b\u4f3c\u4e0b\u9762\u8fd9\u6837<\/p>\n<pre class=\"lang:c# decode:true\">ES2.Save(data, \"C:\/Users\/User\/myFile.txt\");    \/\/ \u8fd9\u91ccmyFile.txt\u53ea\u5b58\u50a8data\r\nES2.Save(transform.position, \"C:\/Users\/User\/myFile.txt?tag=myPosition\");   \/\/ \u5728myFile.txt\u6587\u4ef6\u91cc\u63d2\u5165key:myPosition\u5bf9\u5e94value:transform.position\r\ntransform.position = ES2.Load&lt;Vector3&gt;(\"C:\/Users\/User\/myFile.txt?tag=myPosition\"); \u4ecemyFile.txt\u6587\u4ef6\u91cc\u8bfb\u53d6key:myPosition\u7684value\r\n<\/pre>\n<p>\u4e5f\u53ef\u4ee5\u5b58\u50a8\u5230web<\/p>\n<pre class=\"lang:c# decode:true \">    public IEnumerator UploadMesh(Mesh mesh, string tag)\r\n    {\r\n        \/\/ Create a URL and add parameters to the end of it.\r\n        string myURL = \"http:\/\/www.server.com\/ES2.php\";\r\n        myURL += \"?webfilename=myFile.txt&amp;webusername=user&amp;webpassword=pass\";\r\n\r\n        \/\/ Create our ES2Web object.\r\n        ES2Web web = new ES2Web(myURL + \"&amp;tag=\" + tag);\r\n\r\n        \/\/ Start uploading our data and wait for it to finish.\r\n        yield return StartCoroutine(web.Upload(mesh));\r\n\r\n        if (web.isError)\r\n        {\r\n            \/\/ Enter your own code to handle errors here.\r\n            Debug.LogError(web.errorCode + \":\" + web.error);\r\n        }\r\n    }\r\n\r\n    public IEnumerator DownloadMesh(string tag)\r\n    {\r\n        \/\/ Create a URL and add parameters to the end of it.\r\n        string myURL = \"http:\/\/www.server.com\/ES2.php\";\r\n        myURL += \"?webfilename=myFile.txt&amp;webusername=user&amp;webpassword=pass\";\r\n\r\n        \/\/ Create our ES2Web object.\r\n        ES2Web web = new ES2Web(myURL + \"&amp;tag=\" + tag);\r\n\r\n        \/\/ Start downloading our data and wait for it to finish.\r\n        yield return StartCoroutine(web.Download());\r\n\r\n        if (web.isError)\r\n        {\r\n            \/\/ Enter your own code to handle errors here.\r\n            Debug.LogError(web.errorCode + \":\" + web.error);\r\n        }\r\n        else\r\n        {\r\n            \/\/ We could save our data to a local file and load from that.\r\n            web.SaveToFile(\"myFile.txt\");\r\n\r\n            \/\/ Or we could just load directly from the ES2Web object.\r\n            this.GetComponent&lt;MeshFilter&gt;().mesh = web.Load&lt;Mesh&gt;(tag);\r\n        }\r\n    }<\/pre>\n<p>\u800c\u4e14\u5728\u5b58\u50a8\u548c\u8bfb\u53d6\u57fa\u672c\u90fd\u662f\u4e00\u6761\u547d\u4ee4\u641e\u5b9a\uff0c\u5f88\u65b9\u4fbf\u3002\u5f53\u7136\u6570\u636e\u90fd\u662f\u7ecf\u8fc7\u52a0\u5bc6\u5b58\u50a8\u7684<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\u5728\u5b58\u50a8Texture\u65f6\uff0c\u9700\u8981\u628a\u56fe\u7247\u7c7b\u578b\u6539\u6210\u201cAdvanced\u201d\uff0c\u5e76\u52fe\u9009\u201cRead\/Write Enabled\u201d<\/p>\n<p><a href=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/02\/QQ\u622a\u56fe20170204162600.png\" data-lightbox=\"image_lg\"><img title=\"\u6700\u597d\u7528\u7684\u6570\u636e\u5b58\u50a8Easy Save2\u8bb2\u89e3 - \u7b2c5\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"\u6700\u597d\u7528\u7684\u6570\u636e\u5b58\u50a8Easy Save2\u8bb2\u89e3 - \u7b2c5\u5f20  | u3d8\u6280\u672f\u5206\u4eab\"  loading=\"lazy\" class=\"aligncenter size-full wp-image-1001\"  data-src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/02\/QQ\u622a\u56fe20170204162600.png\" width=\"328\" height=\"215\" srcset=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/02\/QQ\u622a\u56fe20170204162600.png 328w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/02\/QQ\u622a\u56fe20170204162600-300x197.png 300w\" sizes=\"(max-width: 328px) 100vw, 328px\" \/><\/a><\/p>\n<p>\u4e0b\u9762\u7ed9\u5927\u5bb6\u5206\u4eab\u4e0b\u6211\u6d4b\u8bd5\u7684\u51e0\u4e2a\u7c7b\u578b<\/p>\n<pre class=\"lang:c# decode:true  \">using UnityEngine;\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\nusing UnityEngine.UI;\r\n\r\n\r\npublic class SaveTest : MonoBehaviour {\r\n\r\n    public Image image;\r\n\r\n    public void Save()\r\n    {\r\n        ES2.Save(123, \"IntData\");\r\n\r\n        ES2.Save(1.23f, \"FloatData\");\r\n\r\n        ES2.Save(true, \"BoolData\");\r\n\r\n        ES2.Save(\"abc\", \"StringData\");\r\n\r\n        ES2.Save(new Vector3(10, 20, 30), \"Vector3Data\");\r\n\r\n        \/\/ \u5b58\u50a8transform\r\n        GameObject go = new GameObject();\r\n        go.transform.localPosition = new Vector3(10, 20, 30);\r\n        go.transform.localScale = new Vector3(3, 3, 3);\r\n        ES2.Save(go.transform, \"TransformData\");\r\n\r\n        \/\/ \u5b58\u50a8\u6570\u7ec4\r\n        int[] intArray = new int[3] { 3, 2, 1 };\r\n        ES2.Save(intArray, \"IntArrayData\");\r\n\r\n        \/\/ \u5b58\u50a8\u96c6\u5408\r\n        List&lt;string&gt; stringList = new List&lt;string&gt;();\r\n        stringList.Add(\"stringlist1\");\r\n        stringList.Add(\"stringlist2\");\r\n        stringList.Add(\"stringlist3\");\r\n        ES2.Save(stringList, \"StringListData\");\r\n\r\n        \/\/ \u5b58\u50a8\u5b57\u5178\r\n        Dictionary&lt;int, string&gt; stringDict = new Dictionary&lt;int, string&gt;();\r\n        stringDict.Add(1, \"a\");\r\n        stringDict.Add(2, \"b\");\r\n        ES2.Save(stringDict, \"StringDictData\");\r\n\r\n        \/\/ \u5b58\u50a8\u6808\r\n        Stack&lt;string&gt; stringStack = new Stack&lt;string&gt;();\r\n        stringStack.Push(\"aaa\");\r\n        stringStack.Push(\"bbb\");\r\n        ES2.Save(stringStack, \"StringStackData\");\r\n\r\n        ES2.SaveImage(image.sprite.texture, \"MyImage.png\");\r\n    }\r\n\r\n    public void Load()\r\n    {\r\n        int loadInt = ES2.Load&lt;int&gt;(\"IntData\");\r\n        Debug.Log(\"\u8bfb\u53d6\u7684int\uff1a\" + loadInt);\r\n\r\n        float loadFloat = ES2.Load&lt;float&gt;(\"FloatData\");\r\n        Debug.Log(\"\u8bfb\u53d6\u7684float\uff1a\" + loadFloat);\r\n\r\n        bool loadBool = ES2.Load&lt;bool&gt;(\"BoolData\");\r\n        Debug.Log(\"\u8bfb\u53d6\u7684bool\uff1a\" + loadBool);\r\n\r\n        string loadString = ES2.Load&lt;string&gt;(\"StringData\");\r\n        Debug.Log(\"\u8bfb\u53d6\u7684string\uff1a\" + loadString);\r\n\r\n        Vector3 loadVector3 = ES2.Load&lt;Vector3&gt;(\"Vector3Data\");\r\n        Debug.Log(\"\u8bfb\u53d6\u7684vector3\uff1a\" + loadVector3);\r\n\r\n        Transform loadTransform = ES2.Load&lt;Transform&gt;(\"TransformData\");\r\n        Debug.Log(\"\u8bfb\u53d6\u7684transform\uff1a \u5750\u6807\" + loadTransform.localPosition + \" \u7f29\u653e\" + loadTransform.localScale);\r\n\r\n        \/\/ \u8bfb\u53d6\u6570\u7ec4\u683c\u5f0f\u5b58\u50a8\r\n        int[] loadIntArray = ES2.LoadArray&lt;int&gt;(\"IntArrayData\");\r\n        foreach (int i in loadIntArray)\r\n        {\r\n            Debug.Log(\"\u8bfb\u53d6\u7684\u6570\u7ec4\uff1a\" + i);\r\n        }\r\n\r\n        \/\/ \u8bfb\u53d6\u96c6\u5408\u683c\u5f0f\u5b58\u50a8\r\n        List&lt;string&gt; loadStringList = ES2.LoadList&lt;string&gt;(\"StringListData\");\r\n        foreach (string s in loadStringList)\r\n        {\r\n            Debug.Log(\"\u8bfb\u53d6\u7684\u96c6\u5408\u6570\u636e\uff1a\" + s);\r\n        }\r\n\r\n        \/\/ \u8bfb\u53d6\u5b57\u5178\u683c\u5f0f\u5b58\u50a8\r\n        Dictionary&lt;int, string&gt; loadStringDict = ES2.LoadDictionary&lt;int, string&gt;(\"StringDictData\");\r\n        foreach (var item in loadStringDict)\r\n        {\r\n            Debug.Log(\"\u8bfb\u53d6\u7684\u5b57\u5178\u6570\u636e\uff1a key\" + item.Key + \" value\" + item.Value);\r\n        }\r\n\r\n        Stack&lt;string&gt; loadStringStack = ES2.LoadStack&lt;string&gt;(\"StringStackData\");\r\n        foreach (string ss in loadStringStack)\r\n        {\r\n            Debug.Log(\"\u8bfb\u53d6\u7684\u6808\u5185\u6570\u636e\uff1a\" + ss);\r\n        }\r\n\r\n        Texture2D tex = ES2.LoadImage(\"MyImage.png\");\r\n        Sprite temp = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0, 0));\r\n        image.sprite = temp;\r\n\r\n        \/\/ \u5224\u65ad\u662f\u5426\u6709\u8be5\u5b58\u50a8key\r\n        Debug.Log(ES2.Exists(\"IntData\"));\r\n\r\n        \/\/ \u5220\u9664\u5b58\u50a8key\r\n        ES2.Delete(\"IntData\");\r\n    }\r\n\r\n\r\n}\r\n<\/pre>\n<p>\u9644\u4e0a\u4e0b\u8f7d\u94fe\u63a5:https:\/\/pan.baidu.com\/s\/1o8dMZpg \u5bc6\u7801:sq66 \u00a0 \u63d2\u4ef6\u4ec5\u7528\u4e8e\u5b66\u4e60\uff0c\u7981\u6b62\u5546\u7528\uff0c\u4e3a\u4e86\u7ef4\u62a4\u60a8\u7684\u4e2a\u4eba\u6743\u76ca\uff0c\u8bf7\u652f\u6301\u6b63\u7248<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u62bd\u65f6\u95f4\u5b66\u4e60\u4e86\u201cEasy Save2\u201d\u63d2\u4ef6\uff0c\u7248\u672cv2.6.3 \u00a0\u6211\u4e2a\u4eba\u89c9\u5f97\u8fd9\u4e2a &hellip; <a href=\"http:\/\/www.u3d8.com\/?p=1000\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24,23],"tags":[234,232,233],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1000"}],"collection":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1000"}],"version-history":[{"count":12,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1000\/revisions"}],"predecessor-version":[{"id":1019,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1000\/revisions\/1019"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1000"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}