void DrawTableDetails(Rect position, Rect rowPosition, SerializedProperty property) { if (!property.isExpanded) { return; } EditorGUI.indentLevel++; // Table selection var tableSelectionPos = m_Property.SelectedTableIndex != 0 ? new Rect(rowPosition.x, rowPosition.y, rowPosition.width - k_OpenTableEditorButtonWidth, rowPosition.height) : rowPosition; EditorGUI.BeginChangeCheck(); var selectedTableIndex = EditorGUI.Popup(tableSelectionPos, Styles.selectedTable, m_Property.SelectedTableIndex, ProjectTableLabels); if (EditorGUI.EndChangeCheck()) { m_Property.SelectedTableIndex = selectedTableIndex; } if (m_Property.SelectedTableIndex != 0) { var openTableEditorPos = new Rect(tableSelectionPos.xMax, tableSelectionPos.y, k_OpenTableEditorButtonWidth, tableSelectionPos.height); if (GUI.Button(openTableEditorPos, EditorIcons.StringTable)) { LocalizationTablesWindow.ShowWindow(m_Property.SelectedTableCollection); } } rowPosition.y += rowPosition.height; var buttonPos = new Rect(rowPosition.x + EditorGUIUtility.labelWidth, rowPosition.y, rowPosition.width - EditorGUIUtility.labelWidth, rowPosition.height); if (selectedTableIndex == 0) { if (GUI.Button(buttonPos, Styles.addTableCollection, EditorStyles.miniButton)) { LocalizationTablesWindow.ShowTableCreator(); } } else { if (GUI.Button(buttonPos, Styles.addTableEntry, EditorStyles.miniButton)) { // Attempt to create a new key with a set default name var keys = m_Property.SelectedTableCollection.SharedData; const string newKeyName = "New Entry"; var keyToTry = newKeyName; SharedTableData.SharedTableEntry entry = null; int counter = 1; while (entry == null) { if (keys.Contains(keyToTry)) { keyToTry = $"{newKeyName} {counter++}"; } else { Undo.RecordObject(keys, "Add entry."); entry = keys.AddKey(keyToTry); EditorUtility.SetDirty(keys); } } m_Property.SelectedTableEntry = entry; LocalizationEditorSettings.EditorEvents.RaiseTableEntryAdded(m_Property.SelectedTableCollection, entry); } } rowPosition.y += rowPosition.height; buttonPos.y = rowPosition.y; if (GUI.Button(buttonPos, Styles.addLocale)) { LocaleGeneratorWindow.ShowWindow(); } rowPosition.y += rowPosition.height + EditorGUIUtility.standardVerticalSpacing; if (m_Property.SelectedTableEntry != null) { DrawTableEntryDetails(ref rowPosition, position); } EditorGUI.indentLevel--; }
void DrawTableDetails(Rect position, Rect rowPosition, Data data, SerializedProperty property) { if (!property.isExpanded) { return; } EditorGUI.indentLevel++; // Table selection var tableSelectionPos = data.SelectedTableIndex != 0 ? new Rect(rowPosition.x, rowPosition.y, rowPosition.width - k_OpenTableEditorButtonWidth, rowPosition.height) : rowPosition; EditorGUI.BeginChangeCheck(); var selectedTableIndex = EditorGUI.Popup(tableSelectionPos, Styles.selectedTable, data.SelectedTableIndex, ProjectTableLabels); if (EditorGUI.EndChangeCheck()) { data.SelectedTableIndex = selectedTableIndex; } if (data.SelectedTableIndex != 0) { var openTableEditorPos = new Rect(tableSelectionPos.xMax, tableSelectionPos.y, k_OpenTableEditorButtonWidth, tableSelectionPos.height); if (GUI.Button(openTableEditorPos, EditorIcons.StringTable)) { LocalizationTablesWindow.ShowWindow(data.SelectedTableCollection); } } rowPosition.y += rowPosition.height; var buttonPos = new Rect(rowPosition.x + EditorGUIUtility.labelWidth, rowPosition.y, rowPosition.width - EditorGUIUtility.labelWidth, rowPosition.height); if (selectedTableIndex == 0) { if (GUI.Button(buttonPos, Styles.addTableCollection, EditorStyles.miniButton)) { LocalizationTablesWindow.ShowTableCreator(); } } else { if (GUI.Button(buttonPos, Styles.addTableEntry, EditorStyles.miniButton)) { // Attempt to create a new key with a set default name var keys = data.SelectedTableCollection.SharedData; Undo.RecordObject(keys, "Add entry."); var entry = keys.AddKey(); EditorUtility.SetDirty(keys); data.SelectedTableEntry = entry; LocalizationEditorSettings.EditorEvents.RaiseTableEntryAdded(data.SelectedTableCollection, entry); } } rowPosition.y += rowPosition.height; buttonPos.y = rowPosition.y; if (GUI.Button(buttonPos, Styles.addLocale)) { LocaleGeneratorWindow.ShowWindow(); } rowPosition.MoveToNextLine(); if (data.SelectedTableEntry != null) { DrawTableEntryDetails(ref rowPosition, data, position); } EditorGUI.indentLevel--; }