Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback on value change #45

Open
Nrosa01 opened this issue Mar 29, 2024 · 0 comments
Open

Callback on value change #45

Nrosa01 opened this issue Mar 29, 2024 · 0 comments

Comments

@Nrosa01
Copy link

Nrosa01 commented Mar 29, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant