Gentlymad-Studios / NewGraph

A general node graph solution centered on data management. This is based on the idea to visualize complex data structures as graph networks without having to modify already established data classes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Callback on value change

Nrosa01 opened this issue · comments

I'm trying to change node background depending on a variable, this makes things easier for me. But sadly I can't find a callback to hook, I'm currently using graph callback so if I click anything that is not a field it will be triggered

[CustomNodeEditor(typeof(RoomNode))]
public class RoomNodeEditor : NodeEditor
{
    private void Recolor(NodeController nodeController)
    {
        RoomNode room = nodeController.nodeItem.nodeData as RoomNode;
        nodeController.nodeView.style.backgroundColor = room.roomType switch
        {
            RoomNode.RoomType.Start => Color.green,
            RoomNode.RoomType.Hub => Color.white,
            RoomNode.RoomType.Normal => Color.gray,
            RoomNode.RoomType.MiniBoss => new Color(1, 0.682f, 0.125f),
            RoomNode.RoomType.Reward => Color.yellow,
            RoomNode.RoomType.Boss => Color.red,
            _ => throw new NotImplementedException(),
        };
    }

    public override void Initialize(NodeController nodeController)
    {
        Recolor(nodeController);

        //nodeController.graphController.graphView.OnAction += (action, obj) => { Recolor(nodeController); };
        nodeController.graphController.graphView.OnMouseDown += (mouseInput) => { Recolor(nodeController); };
        nodeController.graphController.graphView.OnAction += (action, obj) => { Recolor(nodeController); };
    }
}

It would be useful for this and similar features to have a callback for when any property of the node changes