alelievr / NodeGraphProcessor

Node graph editor framework focused on data processing using Unity UIElements and C# 4.6
https://github.com/alelievr/NodeGraphProcessor/projects/2
MIT License
2.3k stars 384 forks source link

Add UnityEvent Field Drawer #163

Closed Nerglej closed 3 years ago

Nerglej commented 3 years ago

I've gone through loads of Unity forums, trying to implement it myself, but NodeGraphProcessor is UIElements based, and Unity currently only supports UnityEvents in the inspector, with IMGUI.

Right now I'm stuck implementing it.

So I'm asking for help, implementing a FieldDrawer for UnityEvents.

alelievr commented 3 years ago

You can use an IMGUIContainer to render IMGUI stuff inside UIElements: https://docs.unity3d.com/ScriptReference/UIElements.IMGUIContainer.html

But I'm not sure if it's possible to manually draw the UnityEvent field.

I guess the best option here would be to use the built-in unity drawer with a PropertyField but it requires consequent changes. That would also fix #160 btw.

alelievr commented 3 years ago

Okay, I managed to finish the implementation of SerializedProperties in the node views so now all the builtin Unity property drawers are supported including the UnityEvent one :)

image

using UnityEngine;
using GraphProcessor;
using UnityEngine.Events;

[System.Serializable, NodeMenuItem("Custom/Unity Event Node")]
public class UnityEventNode : BaseNode
{
    [Input(name = "In")]
    public float                input;

    [Output(name = "Out")]
    public float                output;

    public UnityEvent           evt;

    public override string      name => "Unity Event Node";
}