{"id":2057,"date":"2023-01-24T22:34:10","date_gmt":"2023-01-24T14:34:10","guid":{"rendered":"https:\/\/courtship.top\/?p=2057"},"modified":"2023-01-24T22:34:10","modified_gmt":"2023-01-24T14:34:10","slug":"%e4%ba%8c%e8%bf%9b%e5%88%b6%e6%a0%bc%e5%bc%8f%e5%ba%8f%e5%88%97%e5%8c%96%e4%b8%8e%e5%8f%8d%e5%ba%8f%e5%88%97%e5%8c%96-unity%e6%9c%ac%e5%9c%b0%e6%95%b0%e6%8d%ae%e5%ad%98%e5%82%a8","status":"publish","type":"post","link":"https:\/\/courtship.top\/index.php\/2023\/01\/24\/%e4%ba%8c%e8%bf%9b%e5%88%b6%e6%a0%bc%e5%bc%8f%e5%ba%8f%e5%88%97%e5%8c%96%e4%b8%8e%e5%8f%8d%e5%ba%8f%e5%88%97%e5%8c%96-unity%e6%9c%ac%e5%9c%b0%e6%95%b0%e6%8d%ae%e5%ad%98%e5%82%a8\/","title":{"rendered":"\u4e8c\u8fdb\u5236\u683c\u5f0f\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316 Unity\u672c\u5730\u6570\u636e\u5b58\u50a8"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u5e8f\u5217\u5316<\/h2>\n\n\n\n<p><strong>\u5e8f\u5217\u5316<\/strong>\uff1a\u628a\u5bf9\u8c61\u8f6c\u5316\u4e3a\u53ef\u4f20\u8f93\u7684\u5b57\u8282\u5e8f\u5217\u8fc7\u7a0b\u79f0\u4e3a\u5e8f\u5217\u5316\u3002\u901a\u4fd7\u8bf4\u5c31\u662f\u5c06\u4e00\u4e2a\u5bf9\u8c61\u7684\u72b6\u6001\uff08\u5404\u4e2a\u5c5e\u6027\u91cf\uff09\u4fdd\u5b58\u8d77\u6765\uff0c\u7136\u540e\u5728\u9002\u5f53\u7684\u65f6\u5019\u518d\u83b7\u5f97\u3002<br \/><br \/><strong>\u53cd\u5e8f\u5217\u5316<\/strong>\uff1a\u628a\u5b57\u8282\u5e8f\u5217\u8fd8\u539f\u4e3a\u5bf9\u8c61\u7684\u8fc7\u7a0b\u79f0\u4e3a\u53cd\u5e8f\u5217\u5316\u3002<br \/><br \/>\u5e8f\u5217\u5316\u53ea\u662f\u4e00\u79cd\u62c6\u88c5\u7ec4\u88c5\u5bf9\u8c61\u7684\u89c4\u5219\uff0c\u90a3\u4e48\u8fd9\u79cd\u89c4\u5219\u80af\u5b9a\u4e5f\u53ef\u80fd\u6709\u591a\u79cd\u591a\u6837\uff0c\u6bd4\u5982\u73b0\u5728\u5e38\u89c1\u7684\u5e8f\u5217\u5316\u65b9\u5f0f\u6709\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>JDK\uff08\u4e0d\u652f\u6301\u8de8\u8bed\u8a00\uff09<\/li>\n\n\n\n<li>JSON\u3001XML\u3001Hessian<\/li>\n\n\n\n<li>Kryo\uff08\u4e0d\u652f\u6301\u8de8\u8bed\u8a00\uff09<\/li>\n\n\n\n<li>Thrift\u3001Protostuff<\/li>\n\n\n\n<li>FST\uff08\u4e0d\u652f\u6301\u8de8\u8bed\u8a00\uff09<\/li>\n<\/ul>\n\n\n\n<p>\u5e8f\u5217\u5316\u76ee\u7684\uff1a\u4ee5\u67d0\u79cd\u5b58\u50a8\u5f62\u5f0f\u4f7f\u81ea\u5b9a\u4e49\u5bf9\u8c61\u6301\u4e45\u5316\uff0c\u5c06\u5bf9\u8c61\u4ece\u4e00\u4e2a\u5730\u65b9\u4f20\u9012\u5230\u53e6\u4e00\u4e2a\u5730\u65b9\uff0c\u4e3a\u4e86\u5bf9\u8c61\u53ef\u4ee5\u8de8\u5e73\u53f0\u5b58\u50a8\uff0c\u548c\u8fdb\u884c\u7f51\u7edc\u4f20\u8f93\uff08\u51e1\u662f\u9700\u8981\u8fdb\u884c\u201c\u8de8\u5e73\u53f0\u5b58\u50a8\u201d\u548c\u201d\u7f51\u7edc\u4f20\u8f93\u201d\u7684\u6570\u636e\uff0c\u90fd\u9700\u8981\u8fdb\u884c\u5e8f\u5217\u5316\uff09<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u65b9\u6cd5<\/h2>\n\n\n\n<p>\u7528\u4e8c\u8fdb\u5236\u683c\u5f0f\u5316\u7684\u5e8f\u5217\u5316\u65b9\u6cd5\u6765\u5e8f\u5217\u5316Save\u5bf9\u8c61\uff0c\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316\u7684\u8fdb\u884c\u9700\u8981\u4f9d\u6258\u6587\u4ef6\u6d41(FileStream)\u8fdb\u884c<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"> \u5e8f\u5217\u5316\uff08\u4fdd\u5b58\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>BinaryFormatter.Serialize(FileStream _fileStream, Object _object)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>FileStream fs = new FileStream(\"DataFile.dat\", FileMode.Create);\nBinaryFormatter formatter = new BinaryFormatter();\n\nfirmatter.Serialize(fs,addresses)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u53cd\u5e8f\u5217\u5316\uff08\u8bfb\u53d6\uff09<\/h3>\n\n\n\n<p>\u4e8c\u8fdb\u5236\u683c\u5f0f\u5316\u7a0b\u5e8f\u7684\u53cd\u5e8f\u5217\u5316\u65b9\u6cd5\uff0c\u5c06\u6587\u4ef6\u6d41\u8f6c\u6362\u4e3a\u4e00\u4e2asave\u5bf9\u8c61<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Save save = (Save)BinaryFormatter.Deserialize(FileStream _fileStream); \/\/\u5f3a\u8f6c<\/code><\/pre>\n\n\n\n<p>Hashtable addresses = null;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FileStream fs = new FileStream(\"DataFile.dat\", FileMode.Open);\ntry\n{\n    BinaryFormatter formatter = new BinaryFormatter();\n    addresses = (Hashtable) formatter.Deserialize(fs);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6848\u4f8b<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public class App\n{\n    &#91;STAThread]\n    static void Main()\n    {\n        Serialize();\n        Deserialize();\n    }\n\n    static void Serialize()\n    {\n        \/\/ Create a hashtable of values that will eventually be serialized.\n        Hashtable addresses = new Hashtable();\n        addresses.Add(\"Jeff\", \"123 Main Street, Redmond, WA 98052\");\n        addresses.Add(\"Fred\", \"987 Pine Road, Phila., PA 19116\");\n        addresses.Add(\"Mary\", \"PO Box 112233, Palo Alto, CA 94301\");\n\n        \/\/ To serialize the hashtable and its key\/value pairs,\n        \/\/ you must first open a stream for writing.\n        \/\/ In this case, use a file stream.\n        FileStream fs = new FileStream(\"DataFile.dat\", FileMode.Create);\n\n        \/\/ Construct a BinaryFormatter and use it to serialize the data to the stream.\n        BinaryFormatter formatter = new BinaryFormatter();\n        try\n        {\n            formatter.Serialize(fs, addresses);\n        }\n        catch (SerializationException e)\n        {\n            Console.WriteLine(\"Failed to serialize. Reason: \" + e.Message);\n            throw;\n        }\n        finally\n        {\n            fs.Close();\n        }\n    }\n\n    static void Deserialize()\n    {\n        \/\/ Declare the hashtable reference.\n        Hashtable addresses  = null;\n\n        \/\/ Open the file containing the data that you want to deserialize.\n        FileStream fs = new FileStream(\"DataFile.dat\", FileMode.Open);\n        try\n        {\n            BinaryFormatter formatter = new BinaryFormatter();\n\n            \/\/ Deserialize the hashtable from the file and\n            \/\/ assign the reference to the local variable.\n            addresses = (Hashtable) formatter.Deserialize(fs);\n        }\n        catch (SerializationException e)\n        {\n            Console.WriteLine(\"Failed to deserialize. Reason: \" + e.Message);\n            throw;\n        }\n        finally\n        {\n            fs.Close();\n        }\n\n        \/\/ To prove that the table deserialized correctly,\n        \/\/ display the key\/value pairs.\n\/\/        foreach (DictionaryEntry de in addresses)\n\/\/        {\n\/\/            Console.WriteLine(\"{0} lives at {1}.\", de.Key, de.Value);\n\/\/        }\n\t\taddresses.Dump();\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5e8f\u5217\u5316 \u5e8f\u5217\u5316\uff1a\u628a\u5bf9\u8c61\u8f6c\u5316\u4e3a\u53ef\u4f20\u8f93\u7684\u5b57\u8282\u5e8f\u5217\u8fc7\u7a0b\u79f0\u4e3a\u5e8f\u5217\u5316\u3002\u901a\u4fd7\u8bf4\u5c31\u662f\u5c06\u4e00\u4e2a\u5bf9\u8c61\u7684\u72b6\u6001\uff08\u5404\u4e2a\u5c5e\u6027\u91cf\uff09\u4fdd\u5b58\u8d77\u6765\uff0c\u7136\u540e\u5728\u9002\u5f53\u7684\u65f6\u5019\u518d\u83b7 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[21,13],"tags":[],"class_list":["post-2057","post","type-post","status-publish","format-standard","hentry","category-c-unity","category-unity"],"_links":{"self":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts\/2057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/comments?post=2057"}],"version-history":[{"count":0,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/posts\/2057\/revisions"}],"wp:attachment":[{"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/media?parent=2057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/categories?post=2057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courtship.top\/index.php\/wp-json\/wp\/v2\/tags?post=2057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}