Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Coding Advice Needed: Building a 2D ship editor

Discussion in '2D' started by Catfang007, Apr 6, 2015.

  1. Catfang007

    Catfang007

    Joined:
    May 8, 2014
    Posts:
    5
    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"

    "UI PANES, PANELS AND WINDOWS" https://unity3d.com/learn/tutorials/modules/intermediate/live-training-archive/panels-panes-windows