{"id":2242,"date":"2021-04-14T17:26:00","date_gmt":"2021-04-14T09:26:00","guid":{"rendered":"http:\/\/www.u3d8.com\/?p=2242"},"modified":"2021-05-10T16:28:42","modified_gmt":"2021-05-10T08:28:42","slug":"unity%e4%b9%8beasysave3%e5%ad%98%e5%82%a8%e7%bc%96%e8%be%91%e5%99%a8","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=2242","title":{"rendered":"Unity\u4e4bEasySave3\u5b58\u50a8\u7f16\u8f91\u5668"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><a href=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2021\/05\/localSaveEditor.gif\" data-lightbox=\"image_lg\"><img title=\"Unity\u4e4bEasySave3\u5b58\u50a8\u7f16\u8f91\u5668 - \u7b2c1\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"Unity\u4e4bEasySave3\u5b58\u50a8\u7f16\u8f91\u5668 - \u7b2c1\u5f20  | u3d8\u6280\u672f\u5206\u4eab\"  loading=\"lazy\" width=\"614\" height=\"301\"  data-src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2021\/05\/localSaveEditor.gif\" alt=\"\" class=\"wp-image-2243\"\/><\/a><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>using UnityEngine;\r\nusing UnityEditor;\r\nusing System.Collections.Generic;\r\n\r\npublic class LocalSaveEditor : EditorWindow\r\n{\r\n    class Data{\r\n        public object value;\r\n        public bool isEditing = false;\r\n    }\r\n\r\n    &#91;MenuItem(\"Tools\/Assets\/\u7f16\u8f91\u672c\u5730\u5b58\u50a8\")]\r\n    public static void Open()\r\n    {\r\n        EditorWindow window = EditorWindow.GetWindow(typeof(LocalSaveEditor), false, \"\u7f16\u8f91\u672c\u5730\u5b58\u50a8\");\r\n        window.minSize = new Vector2(600, 200);   \r\n    }\r\n\r\n    private void OnEnable()\r\n    {\r\n        Refresh();\r\n    }\r\n\r\n    private void OnFocus()\r\n    {\r\n        Refresh();\r\n    }\r\n\r\n    private Dictionary&lt;string, Data> keyValues = new Dictionary&lt;string, Data>();\r\n    private Vector2 scrollPosition;\r\n\r\n    void OnGUI()\r\n    {\r\n        EditorGUILayout.Space(5);\r\n        EditorHelper.GUIHorzontalLine(2);\r\n        GUILayout.Label(\"\u672c\u5730\u5b58\u50a8keys\u6570\u91cf\uff1a\" + keyValues.Count);\r\n        if (GUILayout.Button(\"\u5237\u65b0\u5217\u8868\"))\r\n            Refresh();\r\n        EditorHelper.GUIHorzontalLine();\r\n\r\n        if (keyValues.Count > 0)\r\n        {           \r\n            ShowTableTitle();\r\n            ShowTable();\r\n        }\r\n    }\r\n\r\n    private void Refresh()\r\n    {\r\n        keyValues.Clear();\r\n        string&#91;] keys = ES3.GetKeys();\r\n        if (keys == null || keys.Length == 0)\r\n            return;\r\n        for (int i = 0; i &lt; keys.Length; i++)\r\n        {\r\n            keyValues.Add(keys&#91;i], new Data(){value = ES3.Load(keys&#91;i])});\r\n        }\r\n    }\r\n\r\n    private void ShowTableTitle()\r\n    {\r\n        GUILayout.BeginHorizontal(GUILayout.Height(20));\r\n        {\r\n            GUILayout.Label(\"\", GUILayout.Width(61));\r\n            EditorHelper.GUIVerticalLine(2);\r\n            GUILayout.Label(\"key\", GUILayout.Width(150));\r\n            EditorHelper.GUIVerticalLine(2);\r\n            GUILayout.Label(\"value\", GUILayout.Width(150));\r\n            GUILayout.FlexibleSpace();\r\n            EditorHelper.GUIVerticalLine(2);\r\n            GUILayout.Label(\"type\", GUILayout.Width(100));\r\n        }\r\n        GUILayout.EndHorizontal();\r\n\r\n        EditorHelper.GUIHorzontalLine();\r\n\r\n\r\n    }\r\n    private void ShowTable()\r\n    {\r\n        int index = 0;\r\n        scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);\r\n        foreach (var item in keyValues)\r\n        {\r\n            GUILayout.BeginHorizontal(GUILayout.Height(20));\r\n            {\r\n                if (item.Value.isEditing)\r\n                    GUI.backgroundColor = Color.red;\r\n                if (item.Value.isEditing != GUILayout.Toggle(item.Value.isEditing, EditorHelper.SettingIcon, EditorHelper.ToolbarButtonStyle, GUILayout.Width(25)))\r\n                {\r\n                    item.Value.isEditing = !item.Value.isEditing;\r\n                    if (item.Value.isEditing == false)\r\n                    {\r\n                        Debug.Log(item.Value.value);\r\n                        if (item.Value.value.GetType() == typeof(int))\r\n                        {\r\n                            ES3.Save(item.Key, (int)item.Value.value);\r\n                        }\r\n                        else if (item.Value.value.GetType() == typeof(bool))\r\n                        {\r\n                            ES3.Save(item.Key, (bool)item.Value.value);\r\n                        }\r\n                        else if (item.Value.value.GetType() == typeof(string))\r\n                        {\r\n                            ES3.Save(item.Key, (string)item.Value.value);\r\n                        }\r\n                    }\r\n                }\r\n                GUI.backgroundColor = Color.gray * 2f;\r\n                EditorHelper.GUIVerticalLine(2);\r\n                if (GUILayout.Button(EditorHelper.DeleteIcon, EditorHelper.ToolbarButtonStyle))\r\n                {\r\n                    ES3.DeleteKey(item.Key);\r\n                    Refresh();\r\n                    break;\r\n                }\r\n                EditorHelper.GUIVerticalLine(2);\r\n                GUILayout.Label(item.Key, GUILayout.Width(150));\r\n                EditorHelper.GUIVerticalLine(2);\r\n                if (item.Value.isEditing)\r\n                {\r\n                    GUI.backgroundColor = Color.red;\r\n                    if (item.Value.value.GetType() == typeof(int))\r\n                    {\r\n                        item.Value.value = EditorGUILayout.IntField((int)item.Value.value);\r\n                    }\r\n                    else if (item.Value.value.GetType() == typeof(bool))\r\n                    {\r\n                        item.Value.value = EditorGUILayout.Toggle((bool)item.Value.value);\r\n                    }\r\n                    else if (item.Value.value.GetType() == typeof(string))\r\n                    {\r\n                        item.Value.value = GUILayout.TextArea(item.Value.value.ToString());\r\n                    }\r\n                    GUI.backgroundColor = Color.gray * 2f;\r\n                }\r\n                else\r\n                    GUILayout.TextArea(item.Value.value.ToString());\r\n                GUILayout.FlexibleSpace();\r\n                EditorHelper.GUIVerticalLine(2);\r\n                GUILayout.Label(item.Value.value.GetType().ToString(), GUILayout.Width(100));\r\n            }\r\n            GUILayout.EndHorizontal();\r\n            index++;\r\n        }\r\n        EditorGUILayout.EndScrollView();\r\n    }\r\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[297],"tags":[],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/2242"}],"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=2242"}],"version-history":[{"count":1,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/2242\/revisions"}],"predecessor-version":[{"id":2244,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/2242\/revisions\/2244"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2242"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}