void CreateCollection() { var assetDirectory = EditorUtility.SaveFolderPanel("Create Table Collection", "Assets/", ""); if (string.IsNullOrEmpty(assetDirectory)) { return; } LocalizationTableCollection createdCollection = null; if (m_CollectionTypePopup.value == typeof(StringTableCollection)) { createdCollection = LocalizationEditorSettings.CreateStringTableCollection(m_TableCollectionName.value, assetDirectory, GetSelectedLocales()); } if (m_CollectionTypePopup.value == typeof(AssetTableCollection)) { createdCollection = LocalizationEditorSettings.CreateAssetTableCollection(m_TableCollectionName.value, assetDirectory, GetSelectedLocales()); } // Select the root asset and open the table editor window. Selection.activeObject = createdCollection; LocalizationTablesWindow.ShowWindow(createdCollection); InitializeTableName(); }
public override void OnInspectorGUI() { serializedObject.Update(); m_SharedTableDataSerializedObject?.Update(); EditorGUILayout.LabelField("Table Collection Name", m_TableCollectionName?.stringValue); EditorGUILayout.PropertyField(m_LocaleId); EditorGUILayout.Space(); if (m_Collection == null) { DrawLooseTableGUI(); } else { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(m_CollectionButton, EditorStyles.miniButton, GUILayout.Width(150), GUILayout.Height(EditorGUIUtility.singleLineHeight))) { Selection.activeObject = m_Collection; } if (GUILayout.Button(m_TableEditorButton, EditorStyles.miniButton, GUILayout.Width(150), GUILayout.Height(EditorGUIUtility.singleLineHeight))) { LocalizationTablesWindow.ShowWindow(m_Collection); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button(Styles.removeFromCollection)) { m_Collection.RemoveTable(m_TargetTable, createUndo: true); } if (!string.IsNullOrEmpty(m_MissingSharedDataEntriesWarning)) { EditorGUILayout.Space(); EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.HelpBox(m_MissingSharedDataEntriesWarning, MessageType.Warning); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(Styles.missingEntriesAdd)) { Undo.RecordObject(m_TargetTable.SharedData, "Add Missing Entries"); CheckForEntriesMissingFromSharedTableData(MissingEntryAction.AddEntriesToSharedData); GUIUtility.ExitGUI(); } if (GUILayout.Button(Styles.missingEntriesRemove)) { Undo.RecordObject(m_TargetTable, "Remove Missing Entries"); CheckForEntriesMissingFromSharedTableData(MissingEntryAction.RemoveEntriesFromTable); GUIUtility.ExitGUI(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } } EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); }
void CreateCollection(Func <string, string, IList <Locale>, LocalizedTableCollection> create) { var assetDirectory = EditorUtility.SaveFolderPanel("Create Table Collection", "Assets/", ""); if (string.IsNullOrEmpty(assetDirectory)) { return; } var createdCollection = create(m_TableCollectionName.value, assetDirectory, GetSelectedLocales()); // Select the root asset and open the table editor window. Selection.activeObject = createdCollection; LocalizationTablesWindow.ShowWindow(createdCollection); }
public override void OnInspectorGUI() { serializedObject.Update(); m_SharedTableDataSerializedObject?.Update(); EditorGUILayout.LabelField("Table Collection Name", m_TableCollectionName?.stringValue); EditorGUILayout.PropertyField(m_LocaleId); EditorGUILayout.Space(); if (m_Collection == null) { DrawLooseTableGUI(); } else { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(m_CollectionButton, EditorStyles.miniButton, GUILayout.Width(150), GUILayout.Height(EditorGUIUtility.singleLineHeight))) { Selection.activeObject = m_Collection; } if (GUILayout.Button(m_TableEditorButton, EditorStyles.miniButton, GUILayout.Width(150), GUILayout.Height(EditorGUIUtility.singleLineHeight))) { LocalizationTablesWindow.ShowWindow(m_Collection); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button(Styles.removeFromCollection)) { m_Collection.RemoveTable(m_TargetTable, true); } } EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); }
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--; }
public override void OnInspectorGUI() { serializedObject.Update(); if (m_Collection.SharedData == null) { EditorGUILayout.HelpBox(Styles.missingSharedTableData, MessageType.Error); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_SharedTableData); if (EditorGUI.EndChangeCheck()) { RefreshTables(); } return; } m_Tables.isExpanded = EditorGUILayout.Foldout(m_Tables.isExpanded, Styles.tables, true); if (m_Tables.isExpanded) { EditorGUI.indentLevel++; var tables = m_Collection.Tables; for (int i = 0; i < tables.Count; ++i) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(tables[i].asset?.name, EditorStyles.label)) { EditorGUIUtility.PingObject(tables[i].asset); } if (GUILayout.Button(Styles.removeTable, GUILayout.Width(60))) { m_Collection.RemoveTable(tables[i].asset, createUndo: true); GUIUtility.ExitGUI(); } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; } // Loose tables if (m_LooseTables.Count > 0) { m_ShowLooseTables = EditorGUILayout.Foldout(m_ShowLooseTables, Styles.looseTables); if (m_ShowLooseTables) { EditorGUILayout.HelpBox(Styles.looseTablesInfo); EditorGUI.indentLevel++; for (int i = 0; i < m_LooseTables.Count; ++i) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(m_LooseTables[i].name, EditorStyles.label)) { EditorGUIUtility.PingObject(m_LooseTables[i]); } if (GUILayout.Button(Styles.addTable, GUILayout.Width(50))) { m_Collection.AddTable(m_LooseTables[i], createUndo: true); GUIUtility.ExitGUI(); } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; } } // Missing tables if (m_MissingTables.Count > 0) { m_ShowMissingTables = EditorGUILayout.Foldout(m_ShowMissingTables, Styles.missingTables); if (m_ShowMissingTables) { EditorGUILayout.HelpBox(Styles.missingTablesInfo); EditorGUI.indentLevel++; for (int i = 0; i < m_MissingTables.Count; ++i) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(m_MissingTables[i].name, EditorStyles.label)) { EditorGUIUtility.PingObject(m_MissingTables[i]); } if (GUILayout.Button(Styles.createTable, GUILayout.Width(60))) { m_Collection.AddNewTable(m_MissingTables[i].Identifier); GUIUtility.ExitGUI(); } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; } } if (GUILayout.Button(Styles.editCollection)) { LocalizationTablesWindow.ShowWindow(target as LocalizationTableCollection); } EditorGUILayout.PropertyField(m_Group, Styles.group); m_ExtensionsList.DoLayoutList(); serializedObject.ApplyModifiedProperties(); }
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--; }