LocalizedString in custom GraphView Editor Window

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 :
7990782--1026801--upload_2022-3-24_14-40-20.png

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
7991262--1026864--upload_2022-3-24_17-16-13.png
I tried to add a LocalizedString SerializeField in my Node Class,
7991262--1026858--upload_2022-3-24_17-15-14.png
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.
7991262--1026861--upload_2022-3-24_17-15-41.png
What I want is to replace the highlighted TextField above by a LocalizedString.

Thanks in advance for any help :slight_smile:

What does your code that draw the node contents look like?

In my GraphView inheriting class I call Draw() on my node
7991739--1026918--upload_2022-3-24_20-3-1.png
which add some VisualElements to different containers7991739--1026924--upload_2022-3-24_20-8-29.png
I Add lists, button or texfield to access all my variables by implementing their callback and this is fine cause these are “simple” variables as string or int.
[EDIT] Forgot to attach the CreateTextField Utility I use sorry
7991739--1026930--upload_2022-3-24_20-12-9.png

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