I’m trying to build a 2D ship [in-game] editor, where a player will select parts from collection and assemble them in a drag and drop interface. A player will start with an initial part (say hull) that has hard points (attachment points) on it where other parts may be attached. These in turn may also have hard points where further part attachments may occur. Parts will “snap” to the hard points when dragged near them. The end result will basically be a tree (hierarchy) of parts, where the root node is the base part (hull in this case) and first children are the ones directly linked to the part, and each part having possible child parts itself. Eventually I want to let the player then use/fly the finished product.
I’ve gone through several tutorials (see below) on how to use the new EventSystem to allow for drag and drop, but I’m still at a loss on how to create the “hard points” or how to make the sprites “snap” to them. I’m able to create “slots” where parts could be placed using tutorials aimed at card games, etc., but nothing like what I’m trying to do where a dynamic object is basically being built up. I need a coding strategy that will allow me to create various prefab parts that can be assembled in limited ways. I feel like I’m really close, but I’m missing the final bit on how to script up the hard points and creating code to “snap” to these hard points.
TL;DR Version:
I need:
A way to dynamically assemble 2D sprites into a dynamic object while retaining the assembly hierarchy.
My thoughts:
Script (Class) with List of Points (or something more complex to handle orientation as well) defining what the valid connection points are, as well as handling the connection (“snapping to”) of other parts. I’m not sure how to do this part.
Can anyone help me?
Tutorials used so far:
“Unity UI Drag and Drop Tutorial” Unity UI Drag and Drop Tutorial - YouTube
“UI PANES, PANELS AND WINDOWS” Recorded Video Sessions on UI - Unity Learn