1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
using UnityEngine; using UnityEditor; using System.Collections.Generic; public class LocalSaveEditor : EditorWindow { class Data{ public object value; public bool isEditing = false; } [MenuItem("Tools/Assets/编辑本地存储")] public static void Open() { EditorWindow window = EditorWindow.GetWindow(typeof(LocalSaveEditor), false, "编辑本地存储"); window.minSize = new Vector2(600, 200); } private void OnEnable() { Refresh(); } private void OnFocus() { Refresh(); } private Dictionary<string, Data> keyValues = new Dictionary<string, Data>(); private Vector2 scrollPosition; void OnGUI() { EditorGUILayout.Space(5); EditorHelper.GUIHorzontalLine(2); GUILayout.Label("本地存储keys数量:" + keyValues.Count); if (GUILayout.Button("刷新列表")) Refresh(); EditorHelper.GUIHorzontalLine(); if (keyValues.Count > 0) { ShowTableTitle(); ShowTable(); } } private void Refresh() { keyValues.Clear(); string[] keys = ES3.GetKeys(); if (keys == null || keys.Length == 0) return; for (int i = 0; i < keys.Length; i++) { keyValues.Add(keys[i], new Data(){value = ES3.Load(keys[i])}); } } private void ShowTableTitle() { GUILayout.BeginHorizontal(GUILayout.Height(20)); { GUILayout.Label("", GUILayout.Width(61)); EditorHelper.GUIVerticalLine(2); GUILayout.Label("key", GUILayout.Width(150)); EditorHelper.GUIVerticalLine(2); GUILayout.Label("value", GUILayout.Width(150)); GUILayout.FlexibleSpace(); EditorHelper.GUIVerticalLine(2); GUILayout.Label("type", GUILayout.Width(100)); } GUILayout.EndHorizontal(); EditorHelper.GUIHorzontalLine(); } private void ShowTable() { int index = 0; scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); foreach (var item in keyValues) { GUILayout.BeginHorizontal(GUILayout.Height(20)); { if (item.Value.isEditing) GUI.backgroundColor = Color.red; if (item.Value.isEditing != GUILayout.Toggle(item.Value.isEditing, EditorHelper.SettingIcon, EditorHelper.ToolbarButtonStyle, GUILayout.Width(25))) { item.Value.isEditing = !item.Value.isEditing; if (item.Value.isEditing == false) { Debug.Log(item.Value.value); if (item.Value.value.GetType() == typeof(int)) { ES3.Save(item.Key, (int)item.Value.value); } else if (item.Value.value.GetType() == typeof(bool)) { ES3.Save(item.Key, (bool)item.Value.value); } else if (item.Value.value.GetType() == typeof(string)) { ES3.Save(item.Key, (string)item.Value.value); } } } GUI.backgroundColor = Color.gray * 2f; EditorHelper.GUIVerticalLine(2); if (GUILayout.Button(EditorHelper.DeleteIcon, EditorHelper.ToolbarButtonStyle)) { ES3.DeleteKey(item.Key); Refresh(); break; } EditorHelper.GUIVerticalLine(2); GUILayout.Label(item.Key, GUILayout.Width(150)); EditorHelper.GUIVerticalLine(2); if (item.Value.isEditing) { GUI.backgroundColor = Color.red; if (item.Value.value.GetType() == typeof(int)) { item.Value.value = EditorGUILayout.IntField((int)item.Value.value); } else if (item.Value.value.GetType() == typeof(bool)) { item.Value.value = EditorGUILayout.Toggle((bool)item.Value.value); } else if (item.Value.value.GetType() == typeof(string)) { item.Value.value = GUILayout.TextArea(item.Value.value.ToString()); } GUI.backgroundColor = Color.gray * 2f; } else GUILayout.TextArea(item.Value.value.ToString()); GUILayout.FlexibleSpace(); EditorHelper.GUIVerticalLine(2); GUILayout.Label(item.Value.value.GetType().ToString(), GUILayout.Width(100)); } GUILayout.EndHorizontal(); index++; } EditorGUILayout.EndScrollView(); } } |
- 本文固定链接: http://www.u3d8.com/?p=2242
- 转载请注明: 网虫虫 在 u3d8.com 发表过
作者大大 ,请问 EditorHelper 是自定义的, 在Unity 2020.3.18 没有这个东西。
是的,就是一些样式,可以随便找替代的