Hello everyone,
I’m building a custom Dialogue Nodes based system using the GraphView API similar to GitHub - Wafflus/unity-dialogue-system: A basic node based dialogue system made for Unity.
I would like to replace basics TextFields by LocalizedStrings.
The problem is that I don’t know if there is a UIElement that I can add to my visual tree implementing all functions, basically like the Editor one :

Does anyone knows a simple way to do it?
LocalizedStrings do have property drawers. currently they only have a IMGUI property drawer However it should be possible to get it to work with a IMGUIContainer.
https://docs.unity3d.com/ScriptReference/UIElements.IMGUIContainer-ctor.html
Or just use a PropertyField. Unity - Scripting API: PropertyField
You will need a SerializedProperty for both of these
1 Like
Thanks for your quick answer.
However, I’m not able to access any SerializedProperty in my context.
My class is inheriting from the Node class under ‘UnityEditor.Experimental.GraphView’, I’m drawing manually the UI in a custom Editor Window. Like the following attachment shows

I tried to add a LocalizedString SerializeField in my Node Class,

then write a custom Editor script for my Node but it doesn’t make any effect cause I’m not drawing an inspector window I think.

What I want is to replace the highlighted TextField above by a LocalizedString.
Thanks in advance for any help 
What does your code that draw the node contents look like?
You should be able to do something like this:
Wrap the value in a ScriptableObject then use the property drawer.
public class SerializedInstance : ScriptableObject
{
public LocalizedString localizedString;
}
public LocalizedString myString = new LocalizedString();
SerializedInstance m_Instance;
SerializedObject m_SerializedObject;
SerializedProperty m_SerializedProperty;
VisualElement CreateLocalizedStringNode()
{
if (m_Instance == null)
{
m_Instance = ScriptableObject.CreateInstance<SerializedInstance>();
m_Instance.localizedString = myString;
m_SerializedObject = new SerializedObject(m_Instance);
m_SerializedProperty = m_SerializedObject.FindProperty("localizedString");
}
return new IMGUIContainer(() =>
{
m_SerializedObject.Update();
EditorGUILayout.PropertyField(m_SerializedProperty);
if (m_SerializedObject.ApplyModifiedProperties())
{
myString = m_Instance.localizedString;
}
});
}
Hello,
are there any updates on this topic?
will there be a UI Toolkit implementation soon?
What do you mean? Does the above not work for you?
The solution works. I just thought there might be a nicer solution to program.
Thanks for the quick reply.
No we don’t have a UI toolkit version of the property drawer at the moment. We made some progress with one that is used in the UI builder for the localization bindings but it’s not used for the localized string at the moment. The above solution is still the way to go.
1 Like