Skip to content

Instantly share code, notes, and snippets.

@kaikoga
Created January 9, 2023 09:59
Show Gist options
  • Save kaikoga/0f5de9385a3f461cbcdc6a054fcbd162 to your computer and use it in GitHub Desktop.
Save kaikoga/0f5de9385a3f461cbcdc6a054fcbd162 to your computer and use it in GitHub Desktop.
The best PropertyField implementation for UIElements (considering on-the-fly localization)
using UnityEditor;
using UnityEngine.UIElements;
public class LocalizedPropertyField : VisualElement
{
// Because it is currently the only simple way to dynamically update label content
public LocalizedPropertyField(SerializedProperty property, LocalizedContent locLabel)
{
Add(new IMGUIContainer(() =>
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(property, locLabel.GUIContentInCurrentEditorLocale());
if (EditorGUI.EndChangeCheck()) property.serializedObject.ApplyModifiedProperties();
}));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment