public void AddItem() { ItemEditorWindow itemEditorWindow = ItemEditorWindow.Open(); itemEditorWindow.titleContent = new GUIContent("Add Item"); itemEditorWindow.onFinished = (key, values) => { if (string.IsNullOrEmpty(key)) { EditorUtility.DisplayDialog("Warning", "key不能为空", "OK"); LocalizationEditorWindow.Current.Focus(); return; } if (!LocalizationEditorWindow.Current.DataTable.ContainsKey(key)) { LocalizationEditorWindow.Current.AddItem(key, values); Reload(); } else if (EditorUtility.DisplayDialog("Warning", $"已经包含名为[{key}]的Key,是否替换?", "Yes", "No")) { LocalizationEditorWindow.Current.AddItem(key, values); LanguageTreeViewItem targetItem = keyItems[key] as LanguageTreeViewItem; targetItem.values = values; LocalizationEditorWindow.Current.Focus(); } }; }
protected override void RowGUI(RowGUIArgs args) { LanguageTreeViewItem item = args.item as LanguageTreeViewItem; Rect rect = args.GetCellRect(0); if (multiColumnHeader.IsColumnVisible(0)) { GUI.Label(rect, new GUIContent(item.displayName, item.displayName)); GUI.Box(new Rect(rect.x + rect.width, rect.y, 2, rect.height), ""); } //int showIndex = 1; for (int i = 0; i < item.values.Length; i++) { if (multiColumnHeader.IsColumnVisible(i + 1)) { rect = args.GetCellRect(i + 1); GUI.Label(rect, new GUIContent(item.values[i], item.values[i])); GUI.Box(new Rect(rect.x + rect.width, rect.y, 2, rect.height), ""); //showIndex++; } } }
protected override TreeViewItem BuildRoot() { TreeViewItem root = new TreeViewItem { id = -1, depth = -1, displayName = "Root" }; root.children = new List <TreeViewItem>(); treeViewItemPool.RecycleAll(); idItems.Clear(); keyItems.Clear(); char[] search = Convert.ToString(searchFlags, 2).PadLeft(LocalizationEditorWindow.Current.Languages.Count + 1, '0').ToCharArray(); int id = -1; foreach (KeyValuePair <string, string[]> pair in LocalizationEditorWindow.Current.DataTable) { if (searchFlags == 0) { continue; } //首先匹配Key,若匹配到,则显示此条数据并继续下一条 if (string.IsNullOrEmpty(searchString) || (searchFlags == -1 || search[search.Length - 1] == '1') && pair.Key.ToLower().Contains(searchString.ToLower())) { id++; LanguageTreeViewItem item = treeViewItemPool.Spawn(); //LanguageTreeViewItem item = new LanguageTreeViewItem(id, 0, pair.Key, pair.Value); item.Set(id, 0, pair.Key, pair.Value); idItems[id] = item; keyItems[pair.Key] = item; root.children.Add(item); continue; } for (int i = 0; i < pair.Value.Length; i++) { int index = i; if ((searchFlags == -1 || search[search.Length - index - 2] == '1') && pair.Value[index].ToLower().Contains(searchString.ToLower())) { id++; LanguageTreeViewItem item = new LanguageTreeViewItem(id, 0, pair.Key, pair.Value); idItems[id] = item; keyItems[pair.Key] = item; root.children.Add(item); break; } } } root.children.Sort((left, right) => { for (int i = 0; i < left.displayName.Length; i++) { if (i >= right.displayName.Length || left.displayName[i] > right.displayName[i]) { return(1); } if (left.displayName[i] < right.displayName[i]) { return(-1); } } return(0); }); //foreach (var item in root.children) //{ // Debug.Log((item as LanguageTreeViewItem).values[0]); //} SetupDepthsFromParentsAndChildren(root); return(root); }