I’m attempting to entry the per letter vertices array within the UIElements (UI Toolkit) Label Unity class.
A Label of this kind could be created for instance with:
utilizing UnityEngine.UIElements;
Label label = new Label();
label.textual content = "This can be a check";
label.type.unityFontDefinition = FontDefinition.FromFont(Sources.Load<Font>("font-path"));
label.type.fontSize = 40;
VisualElement rootVE = gameObject.GetComponent<UIDocument>().rootVisualElement;
rootVE.Add(label);
(To make use of this you need to go Sport Object > UI Doc, then proper click on in belongings, create clean UI Doc, and drag it onto sport object’s “supply asset discipline” with this script.)
I’m attempting to get the per letter vertices of a Label of this nature. I used to be instructed by a Unity developer:
“The vertices of letters are presently inner as this space continues to be topic to vary and we’re not prepared to show it publicly. Should you want the info you might entry it by way of reflection, and it’s positioned right here (as of 2022.2) : m_Label.uitkTextHandle.textInfo.”
I can get uitkTextHandle
however cannot discover textInfo
inside it. I’ve tried:
foreach (var propertyInfo in typeof(Label).GetProperties(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Occasion)) { //provides uitkTextHandle
Debug.Log("PROPERTIES " + propertyInfo.Identify);
}
foreach (var propertyInfo in (typeof(Label).GetProperty("uitkTextHandle", System.Reflection.BindingFlags.NonPublic| System.Reflection.BindingFlags.Occasion)).GetType().GetMembers(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Occasion)) { //NO TEXTINFO FOUND
Debug.Log("PROPERTIES " + propertyInfo.Identify);
}
And whereas I can get the uitkTextHandle
this fashion, I can not forged it to entry textInfo inside it (as it’s a protected class) and I in any other case cannot discover any textInfo inside it.
var uitkTextHandle = typeof(Label).GetProperty("uitkTextHandle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Occasion).GetValue(testLabel, null);
Am I doing one thing unsuitable maybe, or may the Unity Admin have given me the unsuitable data? That is my first time utilizing Reflection so I’m not certain.
How would I get the vertices array that they are saying I ought to be capable to this fashion in a format I can use? What am I nonetheless lacking?
Thanks.