Created
January 9, 2023 09:59
-
-
Save kaikoga/0f5de9385a3f461cbcdc6a054fcbd162 to your computer and use it in GitHub Desktop.
The best PropertyField implementation for UIElements (considering on-the-fly localization)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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