Custom Editor (891068)

I have a few questions:

  1. I would like to display the LocalizedString key at the top and on the list after changing the LocalizedString property field. I can only do this by selecting an item from the list again. I need something like “RegisterValueChangedCallback” to change it immediately.

  2. Unity 2022.2. Is it still the only way to create LocalizedString field for a custom editor in UIToolkit?

My code:

        SerializedProperty serializedProperty;
        SerializedProperty serializedProperty2;

        VisualElement CreateLocalizedString(SerializedObject so, SerializedProperty property, string propertyPath)
        {
            property = so.FindProperty(propertyPath);
            return new IMGUIContainer(() =>
            {
                so.Update();
                EditorGUILayout.PropertyField(property);
                so.ApplyModifiedProperties();
            });
        }
        private void OnItemSelection(IEnumerable<object> selectedItems)
        {
            activeItem = (Item)selectedItems.First();

            SerializedObject so = new(activeItem);
            detailSection.Bind(so);

            itemName.text = activeItem.ObjectName.IsEmpty ? "" : GetKey(activeItem.ObjectName);

            if (activeItem.Icon != null)
            {
                itemIcon.style.backgroundImage = activeItem.Icon.texture;
            }

            if (objectName != null)
            {
                detailSection.Remove(objectName);
            }

            if (description != null)
            {
                detailSection.Remove(description);
            }

            objectName = CreateLocalizedString(so, serializedProperty, "ObjectName");
            description = CreateLocalizedString(so, serializedProperty2, "Description");
            detailSection.Add(objectName);
            detailSection.Add(description);

            detailSection.style.visibility = Visibility.Visible;
        }
  1. Is it possible to set the “Active Locale” (Window/Asset Management/Localization Scene Controls) in the script? If so how?

  1. you could try putting the property drawing code between a change check. Unity - Scripting API: EditorGUI.BeginChangeCheck
    This should tell you when a value changes.
  2. we don’t have a UI toolkit version at the moment but one is planned in the future. At the moment it needs to be though imgui, like in your example.
  3. Yes setting LocalizationSettings.SelectedLocale should work.

Thank you for your quick reply.

EditorGUI.EndChangeCheck(); works for Entry Name field but not when selecting string table entry. It’s a bit of a limitation but I think it will be good enough for the item editor.