#Unity Custom Type Drawer

1 messages · Page 1 of 1 (latest)

boreal sedge
#

Hey all! I'm currently trying to make a dialogue system using visual scripting nodes for structure. I'm trying to create a custom data type with a custom inspector/drawer for my node but none of the approaches I've tried have worked.

I've tried the drawer method like how the manual says but all i get is what you see in the screenshot.
I've also tried making an inspector but that also has not worked. Any help would be great thanks!

Here's my drawer attempt:

using UnityEngine;
using UnityEditor;

[CustomPropertyDrawer(typeof(Dialogue))]
public class DialogueDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        var indent = EditorGUI.indentLevel;
        EditorGUI.indentLevel = 0;

        var textRect = new Rect(position.x, position.y, position.width, position.height);

        EditorGUI.PropertyField(textRect, property.FindPropertyRelative("text"), GUIContent.none);

        EditorGUI.indentLevel = indent;
        EditorGUI.EndProperty();
    }
}
inner skiff
#

what kind of dialogue system are you trying to create ? like what is the game that is it for?

#

why would you want a custom data type for a dialogue system? i am sorry if i'm asking stupid question i just want to know

boreal sedge
#

It's a narrative heavy game, basically a visual novel. I already have the base of the dialogue system in place, but I'm using the visual scripting graphs for organizing different routes and such to make it easier for my teammates.

inner skiff
#

ahh i understand, you are trying to simplify it for your team to make modifications?

boreal sedge
#

The data type would contain everything needed to display a certain piece of dialogue, character expression, text, etc

inner skiff
#

i am not sure i would use your way though, i would rather use a scriptable object i think

boreal sedge
inner skiff
#

or a embed script machine with graph variable? a list of strings and a int that says which line to display

boreal sedge
#

The node would just provide the data to the dialogue manager who would handle the rest

inner skiff
inner skiff
boreal sedge
#

yes, the main reason I'm not doing that is so I can make the text area for the dialogue larger

boreal sedge
inner skiff
#

ah okay, i guess i'll leave it to others then, the tool i was talking about would be very good for your use i think though , but it wouldnt combine UVS very well with it i think?

boreal sedge
#

What tool are you suggesting?

inner skiff
#

either that or perhaps use the note to write your dialogue there but keep it close to where the strings are connected?

inner skiff
boreal sedge
# inner skiff Unode

I'd rather write my own solution than pay for one, the only thing that I'm trying to do really is just make a text area inside the node like the [textArea] attribute

inner skiff
inner skiff
boreal sedge
#

Alright, thanks

novel forum
boreal sedge
#

Ah that's unfortunate but I can work with that, how would I make the text area then? Do I just put the attribute on the ValueInput?

novel forum
boreal sedge
#

Awesome! Just two more questions,

  1. Is is possible to have the value to appear next to the port instead of the header?
  2. Does OnValidate(), trigger when it's changed? I'd like to do some input validation when things like enums are changed
novel forum
boreal sedge
#

Cool, I'll be sure to try that out and see. Thanks! I've been learning some of visual scripting and I really wish that i'd get some extra love cause you could do so much with it if there was a little bit more functionality i feel

novel forum
boreal sedge
#

Oooh do tell

novel forum
#

so one of the reason's you could not is because visual scripting blocks setting default values on ports for types that are not basic(int, float, string, Vectors etc)

so you have to manually do it in the definition method:

    protected override void Definition()
    {
        In = ControlInput(nameof(In), Trigger);
        Out = ControlOutput(nameof(Out));
        Save = ValueInput<SaveSystem>(nameof(Save), default);
        if (defaultValues.ContainsKey(Save.key))
        {
            defaultValues[Save.key] = new SaveSystem();
        }
        else
        {
            defaultValues.Add(Save.key, new SaveSystem());
        }
        Succession(In, Out);
    }

then you have to make the inspector for the type

here is my example one

using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;

[Inspector(typeof(SaveSystem))]
public class SaveSystemInspector : Inspector
{
    public SaveSystemInspector(Metadata metadata) : base(metadata)
    {
    }

    protected override float GetHeight(float width, GUIContent label)
    {
        return EditorStyles.textArea.CalcHeight(new GUIContent((metadata.value as SaveSystem).filePath), width);
    }

    protected override void OnGUI(Rect position, GUIContent label)
    {
        BeginBlock(metadata, position);
        var value = metadata.value as SaveSystem;
        var newValue = GUI.TextArea(position, value.filePath);
        if (EndBlock(metadata))
        {
            metadata.RecordUndo();
            metadata["filePath"].value = newValue;
            SetHeightDirty();
        }
    }
}

it makes a text area on the port

boreal sedge
#

Thanks a ton again!

novel forum
#

You're welcome

restive oriole
#

I have a custom dialogue node which you're welcome to look at

#

it will be useless to you as it's bespoke to my framework, but will just confirm for you some of the steps I took

#

But I haven't added custom inspectors to the nodes, so I'm learning some interesting things from this thread, thanks.

restive oriole
#

Unfortunately I was never able to get a nice big text-area to appear for my dialogue

#

but the stuff you're asking about is less about the creation of custom node, and more about how to style and arrange them better, right?