/// <summary> /// Recreates all the GUI elements used by this inspector. /// </summary> private void BuildGUI() { Layout.Clear(); strings.Clear(); StringTable stringTable = InspectedObject as StringTable; if (stringTable == null) { return; } string[] identifiers = stringTable.Identifiers; foreach (var identifier in identifiers) { strings[identifier] = stringTable.GetString(identifier); } languageField = new GUIEnumField(typeof(Language)); languageField.OnSelectionChanged += x => { StringTables.ActiveLanguage = (Language)x; BuildGUI(); Refresh(); }; Layout.AddElement(languageField); valuesField = GUIDictionaryField <string, string, StringTableEntry> .Create( new LocEdString("Strings"), strings, Layout); valuesField.IsExpanded = Persistent.GetBool("valuesField_Expanded"); valuesField.OnExpand += x => Persistent.SetBool("valuesField_Expanded", x); valuesField.OnChanged += x => { if (x != null) { foreach (var KVP in x) { if (stringTable.Contains(KVP.Key)) { string oldValue = stringTable.GetString(KVP.Key); if (oldValue != KVP.Value) { stringTable.SetString(KVP.Key, KVP.Value); } } else { stringTable.SetString(KVP.Key, KVP.Value); } } string[] oldIdentifiers = stringTable.Identifiers; foreach (var identifier in oldIdentifiers) { if (!x.ContainsKey(identifier)) { stringTable.RemoveString(identifier); } } strings = x; } else { foreach (var KVP in strings) { stringTable.RemoveString(KVP.Key); } strings.Clear(); } EditorApplication.SetDirty(stringTable); }; valuesField.OnValueChanged += x => { stringTable.SetString(x, strings[x]); EditorApplication.SetDirty(stringTable); }; valuesField.OnValueRemoved += x => { stringTable.RemoveString(x); EditorApplication.SetDirty(stringTable); }; Layout.AddSpace(10); }