using System; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.Localization.Tables; using UnityEngine.UIElements; using TreeView = UnityEditor.IMGUI.Controls.TreeView; namespace UnityEditor.Localization.UI { /// /// Window used to edit localization tables. /// public class LocalizationTablesWindow : EditorWindow, IHasCustomMenu { const string k_WindowTitle = "Localization Tables"; const string k_Search = "Localization-TablesView-Search"; internal static LocalizationTablesWindow s_Instance; static readonly Vector2 k_MinSize = new Vector2(900, 600); ToolbarMenu m_ImportMenu; ToolbarMenu m_ExportMenu; internal ProjectTablesPopup m_ProjectTablesPopup; Foldout m_CurrentTableFoldout; string m_CurrentTableFoldoutText; VisualElement m_TableDetails; internal TextField m_NameField; Toggle m_PreloadTables; VisualElement m_TableNameHelpBoxContainer; VisualElement m_TableContents; internal ToolbarSearchField m_ToolbarSearchField; IMGUIContainer m_TableContentsImguiContainer; internal TreeView m_TableView; bool m_SelectionChanged; LocalizationTableCollection SelectedCollection { get { if (m_ProjectTablesPopup.value is ProjectTablesPopup.NoTables) return null; return m_ProjectTablesPopup.value; } } /// /// Opens the window in the Editor. /// [MenuItem("Window/Asset Management/Localization Tables")] public static void ShowWindow() { s_Instance = GetWindow(false, null, true); s_Instance.titleContent = EditorGUIUtility.TrTextContent(k_WindowTitle, EditorIcons.TableWindow); s_Instance.Show(); } /// /// Opens the window in the Editor and selects for editing. /// /// public static void ShowWindow(LocalizationTableCollection selectedcollection) { s_Instance = GetWindow(false, null, true); s_Instance.titleContent = EditorGUIUtility.TrTextContent(k_WindowTitle, EditorIcons.TableWindow); s_Instance.Show(true); s_Instance.EditCollection(selectedcollection); } /// /// Opens the window in the Editor and selects the table collection and entry for editing. /// /// The table to select for editing. /// The entry to highlight for editing. public static void ShowWindow(TableReference tableReference, TableEntryReference tableEntryReference) { s_Instance = GetWindow(false, null, true); s_Instance.titleContent = EditorGUIUtility.TrTextContent(k_WindowTitle, EditorIcons.TableWindow); s_Instance.Show(); s_Instance.EditCollection(tableReference, tableEntryReference); } /// /// Opens the window in the Editor with the table creator tab active. /// public static void ShowTableCreator() { ShowWindow(); } /// /// Selects the collection for editing. /// /// public void EditCollection(LocalizationTableCollection selectedCollection) { if (LocalizationEditorSettings.ActiveLocalizationSettings == null) return; m_ProjectTablesPopup.value = selectedCollection; } public void EditCollection(TableReference tableReference, TableEntryReference tableEntryReference) { if (LocalizationEditorSettings.ActiveLocalizationSettings == null) return; var stc = LocalizationEditorSettings.GetStringTableCollection(tableReference); var atc = LocalizationEditorSettings.GetAssetTableCollection(tableReference); SharedTableData.SharedTableEntry entry = null; LocalizationTableCollection collection = stc; if (stc != null) { entry = stc.SharedData.GetEntryFromReference(tableEntryReference); } if (atc != null && entry == null) { collection = atc; entry = atc.SharedData.GetEntryFromReference(tableEntryReference); } m_ProjectTablesPopup.value = collection; m_ToolbarSearchField.value = entry != null ? entry.Id.ToString() : string.Empty; } void OnEnable() { minSize = k_MinSize; var root = rootVisualElement; if (LocalizationEditorSettings.ActiveLocalizationSettings == null) { var asset = Resources.GetTemplateAsset("CreateLocalizationSettings"); asset.CloneTree(root); var button = root.Q