Search Unity

Connect two waypoints in scene view using drag and drop

Discussion in 'Immediate Mode GUI (IMGUI)' started by nicmarxp, Aug 7, 2018.

  1. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    406
    I’m making a waypoint system, where each node has one or more previous and next nodes which makes it possible for the paths to branch. Currently it’s a list of GameObjects, one for previous, and one for next nodes. This is manually set up and it would be really nice to be able to just connect them by dragging in the scene view.

    What I think I want to do first, is make an editor script, so when I select a node, a red (previous) and a green (next) handle is shown.

    The challenge here is to drag from one of the handles and see a visual red/green line connected to the mouse, and then I can release it on another node, and it will add the source nodes to the target list and the other way around. If I release it somewhere else, nothing happens.

    Should I use raycast (screenpointtoworld?) continuosly below the mouse and search for a node, and then somehow highlight it, to visualize that I can drop it?

    The nodes have rectangular colliders, which I guess helps with raycasting.

    I’d be happy for feedback before I start coding this, to see if it’s plausable. I haven’t found any other drag-drop-with-lines features so far, but it seems that it should work.

    Thanks! :)